Fork rule #1
Fork rule #1: After a successful fork, execution in both the parent and child process continues at the instruction following the fork.
Why does it happen this way? Well, think about it: the job of fork is to make a (pretty much) identical copy of the parent in the child; this includes the hardware context (mentioned earlier), which of course includes the Instruction Pointer (IP) register (sometimes called the Program Counter (PC)) itself! Hence, the child process too will execute the user mode code at the same location as the parent. As the fork is successful, control will not go the error handling code (the FATAL() macro); instead, it will go to the printf . The key point is this: this will happen in both the (original) parent ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access