Geeks Geeks:
fork() . fork() , 22 = 4 . 4 . , l fork(), 2l (l + 1). (l + 1).
, fork() 3 . , . 3 23 = 8 , .
C/++:
&& , ||, . , , .
AND (&) , . OR (||) , .
fork():
man fork() ,
" PID , 0. -1, , errno ."
PID unsigned int. , fork() child. . fork(), ,
#include <stdio.h>
int main()
{
fork();
( fork() &&
fork() ) ||
fork();
fork();
printf("forked\n");
return 0;
}
fork() .
0 . (m ) C1, . .
1 m C1 fork() - B. ( , B, C D & ||). B , .
2 - fork() - B, m C1, m C1 , C2 C3 - .
fork() - B , - . & &, - , C2 C3 (fork() - C). m C1 fork() - C. C2 C3 fork() - D, OR.
3 m, C1, C2, C3 C4, C5 . ((B & C) || D), (B & C) . , - . , B && C || D, fork() - D. (B && C), , fork() - D. , C2 C3 2, fork() - D, .
4 m, C1, C2, C3, C4, C5 C6, C7, C8 C9 . fork() - E .
At level 5, 20 processes will be completed. The program (on Ubuntu Maverick, GCC 4.4.5) printed "forked" 20 times. Once parental root (main) and rest by children. A total of 19 processes will be created.