I am doing 3 consecutive forks in a C program.
1. Is it going to execute in the same order ? ( My guess is yes ).
2. If I do a pgrep myexecutable
from shell, would it give the process ids in the same order as they were started ? ( my guess is no, because you cant guarantee what pid the system gives the child, right ? )
There would be a total of 8 processes running after 3 forks are executed
so now the pid would be depend on which order the child process are created by and also in which order the children of children are created.
could be like
main - 12345
child1_of_main_after_fork1 12346
child2_of_child1_after_fork2 12347
child3_of_main_after_fork2 12348
child4_of_main_after_fork3 12349
child5_of_child1_after_fork3 12350
child6_of_child2_after_fork3 12351
child7_of_child3_after_fork3 12352
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With