Concept of fork

How many processes are created in this snippet?
main()
{
Fork();
Fork() && fork () || fork ();
Fork ();
}

Comments

  1. @priyaranjan could you please explain the logic?

    ReplyDelete
  2. @Ankit fork is a system call which generates new thread of execution,and returns pid of newly created thread to parent process and a value of 0 to child process.so here in second statement when fork is called 0 will be returned for child processes so they will not execute second fork in this call.so,doing in the same way you will get 20 as total no of processes created.

    ReplyDelete
  3. http://www.csl.mtu.edu/cs4411/www/NOTES/process/fork/create.html

    ReplyDelete

Post a Comment

Popular posts from this blog