The point of no return

It's important for the systems programmer to understand that, once an exec operation is successful, there is no return to the predecessor process. To illustrate this, consider the rough call graph here:

main()         foo()              exec(something)         bar()

main() calls foo(), which calls exec(something); once the exec is successful, bar() will never run!

Why not? We cannot reach it in the predecessor's execution path as the entire execution context has now changed—to the context of the successor process (something). The PID remains intact though.

Only if the exec fails will the function bar() get control (as, of course, we would still be in the context of the predecessor).

As a further fine point, note that it's possible that the exec() ...

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.