The following sums up important points to note when a predecessor process execs a successor:
- The successor process overwrites (or overlays) the predecessor's virtual address space.
- In effect, the predecessor's text, data, library, and stack segments are now replaced by that of the successor's.
- The OS will take care of the size adjustments.
- No new process has been created—the successor now runs in the context of the old predecessor.
- Several predecessor attributes (including but not limited to the PID and open files) thus get auto-inherited by the successor.
(The astute reader could then question why, in our previous example, the PID of ps is not 3,396 ? Patience, please, we shall have the precise answer on the GitHub repository).
- Several predecessor attributes (including but not limited to the PID and open files) thus get auto-inherited by the successor.
- On a successful exec, there is no possibility of returning to the predecessor; it's gone. Colloquially, performing an exec is like committing suicide for the predecessor: After successful execution, the successor is all that's left; returning to the predecessor is out of the question:
Fig 2: The exec operation