The need to wait

The fork-exec is really interesting, but hang on a second: While the child process performs an exec on the user command, and the successor is running (indicated by the dot-dash blue line in the preceding diagram), what should the parent process do? Obviously, it should wait, but for how long? Should we have it sleep? Well, no, as sleep takes the number of seconds to sleep as its argument. We do not know in advance how long the successor will take (it could be milliseconds, it could be months). The correct thing to do is this: have the parent process wait until the child (now the successor) dies.

This is precisely what the wait(2) API is designed to do. When the parent process issues the wait(2) API, it is put to sleep; the moment its child dies, it's woken up!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset