Wait scenario #3

What if a process has no children, never had any children (a bachelor chap), and it issues the wait(2) API? At first glance, this seems to be a problem case, as perhaps it could cause deadlock; but, no, the kernel is smarter than that. The kernel code of wait checks, and upon finding that the calling process has no children (dead or alive or stopped or whatever), it simply fails the wait. (FYI, errno gets set to ECHILD implying the process had no unwaited-for children).

Again, recall one of our golden rules: never assume anything; always check for the failure case. Importantly, our Chapter 19, Troubleshooting and Best Practices, covers such points.

There is one more wait scenario; however, we need to cover more information ...

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.