fork () creates an exact duplicate of the process that caused the fork () function to be called. This means that you have two processes that are exactly the same and located at the same point in the program. If we go through the fork2 () function, the following will happen.
Process A (source process):
L0 (forks of process A creating process B)
L1 (process A expands again, creating process C)
Goodbye! (process output A)
Process b:
L1 (forks of process B creating process D)
Goodbye! (process B exits)
Process C:
Goodbye! (process C exits)
Process D:
Goodbye! (process D exits)
It depends on the operating system in relation to which process it is running on each fork, and whether it switches to another process at any time during execution, so the output can be alternated at any point after the technological forks. For example, if the OS decided to always follow the new process until the end of the function, you will get the following output:
L0 (A) L1 (B) Bye! (D) Bye! (B) L1 (A) Bye! (C) Bye! (A)
source share