On Wed, 02 Mar 2022 14:44:11 -0300, Meredith Montgomery wrote:
> I took Lew Pitcher's program and gave myself the exercise of just
> switching parent and child's role. Briefly, Lew Pitcher's program forks
> and the child writes data to the parent, which executes less to page the
> output. What you find below is my own writing of that program (with the
> roles switched) --- so all errors are mine, of course.
It looks like a reasonable test program to me. I walked through it and
didn't see any obvious problems.
> I think this program is wrong because the parent doesn't wait for the
> child, so the child finishes ``quickly'' and must be left in a zombie
> state until less exits. When less exits, it does so without calling
> wait(), so the child ends up being wait()ed by the init program. Things
> might end up well, but it's a totally flawed design.
Perhaps not a CYA thorough design, but I wouldn't say "totally flawed".
It /would/ be better to have the parent wait() for the child process, but
since it doesn't, that child process (if it hasn't terminated) becomes an
orphan process, not a zombie. (It would only be a zombie during the lifetime
of the parent process.)
As you alluded to, init(8) is specifically tasked with cleaning up the
status of orphaned child processes. So long as the parent process exits
in a timely manner (and yours does, more or less) there's no need to worry.
Or, to put it another way, so long as the zombie doesn't live /too/ long,
and there aren't /too/ many zombies, the system will live on.
Remember, zombie processes starve the system by holding on to a limited
resource: their place in the system's process state table. The more zombies,
the fewer live processes can run. But, zombie processes are tolerable, so
long as they don't live long enough to impact performance. They may be
undesirable, and (consequently) a sign of "bad design", but so long as they
/do/ die in a reasonable time, you can get away with them.
> That's my understanding. I appreciate if you correct any
> misunderstandings here. Thank you.