Transferring the first full iteration from initialization to all processes ending the first context of the loop, the following will happen:
1. Initializer
i initialized from i = fork();
- Parent process :
i = pid(child1) - Child process child1 :
i = 0
Clicking a conditional test in each process is something interesting.
2. Process: parent
i < fork() , child2. pid(child2) , pid(child1), ,
3. : child1
i
i < fork() , child3. pid(child3) , i ( , ), , child1
4. : child2
i , i pid(child1)i < fork(), fork() eval 0. ...i < fork() child1(pid) < 0, . , for .
5. : child3
i = 0 , child1.i < fork(), fork() eval 0. ...i < fork() 0 < 0, . for.
parent child1 , . (child2 child3) . :
6.
execlp("echo", "sono", argv[0], 0);- child1
execlp("echo", "sono", argv[0], 0); - child2
system("echo i+$i"); . - child3
system("echo i+$i"); .
: for-conditional . , , execlp(). , , system(). , - ( , ), fork() .
, fork().. , , , fork() , .
: , pid-rollover, reset " ", child2 pid, , child1 pid. ( ), :
system("echo i+$i"); .- child1
execlp("echo", "sono", argv[0], 0); - child2
system("echo i+$i"); . - child3
system("echo i+$i"); .
, , , .