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 ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.