"fork" program question.# Unix - 噫吁兮,危乎高哉
w*a
1 楼
Is my analysis for the following program correct? Many thanks.
Line 1) x = 10;
Line 2) if (fork()) x = x+5;
Line 3) if (x % 5 == 0) {
Line 4) if (fork()) x = x + 100;
}
At line 1, x = 10, this is for parent process 0.
At line 2, fork call will build a child process 1, in parent process 0, x =
15, but in child process x=5;
At line 3, both parent process 0 and child proces 1 will enter the if loop.
parent process 0 will build another child process 2, after finishing line 4,
the x in pa
Line 1) x = 10;
Line 2) if (fork()) x = x+5;
Line 3) if (x % 5 == 0) {
Line 4) if (fork()) x = x + 100;
}
At line 1, x = 10, this is for parent process 0.
At line 2, fork call will build a child process 1, in parent process 0, x =
15, but in child process x=5;
At line 3, both parent process 0 and child proces 1 will enter the if loop.
parent process 0 will build another child process 2, after finishing line 4,
the x in pa