The Unix fork-exec semantic
So, that does not work. What we need, really, is a way for our simple shell simpsh to remain alive and well after the exec operation, but how can we achieve that?
The fork is the answer! Here's what we'll do: after the user supplies input (a command), we have our shell fork. We now have two identical shells alive: the original parent (let's say it has PID x) and the brand new child shell (PID y). The child shell is used as the sacrificial lamb: We have it exec the user command. So, yes, the child is the predecessor process that is impossible to return to; but that's OK as we have the parent shell process alive and well!
This well-known technique is called the fork-exec semantic. It combines what several other OSes ...
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