The following C program is executed on a Unix/Linux system :
#include<unistd.h> int main() { int i; for(i=0; i<10; i++) if(i%2 == 0) fork(); return 0; }
The total number of child processes created is ________________ .
5(0,2,4,6,8) times fork is called. Total number of child process would be 2^5−1=31
i is initialized as 0 and it should be incremented by 2 and should go up to less than 10.
consider this code:
for(i=0; i<10; i=i+2)
fork();
fork ( is a function) shall be called 5 times(i=0,2,4,6,8) equal to the no. of even numbers less than 10
∴ Total number of process 2*2*2*2*2 =32
Total number of child process shall be 32−1=31
64.3k questions
77.9k answers
244k comments
80.0k users