11 11 votes find total no of processes i am getting 29 as answer as all will be child process except one parent process plz explain how answer is 24 here i am very confused in such question by drawing diagram #include<stdio.h> #include<stdlib.h> int main(void) { pid_t pid = fork(); pid = fork(); pid = fork(); if(pid == 0) { fork(); } fork(); return 0; } Operating System fork-system-call operating-system + – Kaluti 2.5k views answer comment Share Follow Print See all 9 Comments 9 9 Comments reply Show 6 previous comments Kaluti commented Aug 20, 2017 reply Follow flag @ bikram sir can u explain the answer of this question 0 0 replyShare aehkn commented Aug 20, 2017 reply Follow flag please check explanation below 0 0 replyShare Bikram commented Aug 20, 2017 reply Follow flag see this and draw clear diagram https://gateoverflow.in/3520/how-many-process-created below diagram is clumsy .. 0 0 replyShare Please log in or register to add a comment.
Best answer 4 4 votes Child process = 23 ( count the number of C's in above image) , Root = 1 , this is parent process. Total number of process created = 23 +1 = 24 Bikram answered Aug 20, 2017 • selected Aug 21, 2017 by Kaluti Bikram comment Share Follow See 1 comment 1 1 comment reply Kaluti commented Aug 21, 2017 reply Follow flag thanku sir got it 0 0 replyShare Please log in or register to add a comment.
2 2 votes It's not really complicated! Just read through it! The fork call creates a new process every time that it's called. 0 is given to (child) process and the process id of the child (not zero) is given to original (parent) process. pid_t pid = fork(); // fork #1 pid = fork(); // fork #2 pid = fork(); // fork #3 if (pid == 0) { fork(); // fork #4 } fork(); // fork #5 Fork #1 creates an new processes. You now have (2) processes. Fork #2 is executed by the above (2) processes, creating (2) more processes, for a total of (4). Fork #3 is executed by above (4) processes, creating (4) more processes, for a total of(8). Half of those have pid==0 (childs)and oher half have pid != 0 Fork #4 is executed by half of the processes created by above fork #3 (so,(4) enters if). This creates (4) more additional processes. So (4) + (4) --> due to if condition and the other half that didn't enter if is (4) processes. Totally You now have (12) processes. Fork #5 is executed by all (12) of the remaining processes, creating (12) more processes; you now have twenty-four (12)+(12) --> (24) vishnu priyan answered Dec 21, 2017 vishnu priyan comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes You can ask from this explanation and correct me if am wrong aehkn answered Aug 20, 2017 aehkn comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes pid_t pid = fork(); //Apid = fork(); //Bpid = fork(); //C if(pid == 0){fork(); //D}fork(); //Efork() A, B, C are in sequence so they will create 2^3 = 8 processes. Among those, 4 will be child process and 4 will be parent process. Each parent process will execute only fork() E and will create total of 4*2 = 8 processes.Each child process will execute fork() D & E both in sequence. So, it will be 4 * (2^2) = 16 processes.Total processes = 8 + 16 = 24 manikantsharma answered Jul 8, 2025 manikantsharma comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes inform me if i am wrong Syed_Asimuddin answered Aug 20 Syed_Asimuddin comment Share Follow 0 reply Please log in or register to add a comment.