Creating a new process

The POSIX function to create a process is fork(2). It is an odd function because for each successful call, there are two returns: one in the process that made the call, known as the Parent, and one in the newly created process, known as the Child , as shown in the following diagram:

Immediately after the call, the child is an exact copy of the parent: it has the same stack, the same heap, the same file descriptors, and it executes the same line of code, the one following fork. The only way the programmer can tell them apart is by looking at the return value of fork: it is zero for the child and greater than zero for ...

Get Mastering Embedded Linux Programming - Second Edition 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.