Can anyone help me in understanding how this will created 19 process?
Main()
{
Fork();
Fork() && fork () || fork ();
Fork ();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try to draw a tree of the process creation and study/remember the following points:
P1.
fork()returns the pid (which is bigger tan 0) to the current processand returns 0 in the child process.
P2. you will need to know how the
expression
A() && B() || C()is evaluated; for example ifA()returns0 (false)functionBwill not get evaluated because0 && whateverisalways
0.Now, let’s label the calls to for ease of reference:
I will draw the first level of process creation (and a bit of second level):
The above tree means process [0] (the initial process) will execute the
fork()function numbered 1, 2, 3, and 5. Why didn’tprocess [0]runfork()[4]? Becausefork()[2] && fork[3]evaluate to true already, so no point to evaluatefork()[4].Apply similar concept to the process forked by
fork[1]on the second level to see why processfork[4]was not called.You can complete the process creation tree by applying P1 and P2 at each level of the process creation tree.