wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following C programe 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 _____.

Open in App
Solution

Number of child process created using n fork ()
calls =2n1
  • fork (); statement inside the loop executed when i =0, 2, 4, 6, 8. So n = 5 times fork () is executed.
So, number of child processes created =251=31

flag
Suggest Corrections
thumbs-up
0
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Fundamental Laws of Logarithms
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon