Comment 5 for bug 915158

Revision history for this message
Jilles Tjoelker (jilles) wrote :

You can see the same problem with any shell with a command like

(sleep 3 & exec /bin/sleep 6)

because most versions of /bin/sleep do not clean up zombies (here, a zombie from an inherited child process).

Dash does not consider the existence of a background process a reason to fork for an external command (that needs to be execve()'ed). Therefore you may see zombies if you start some background jobs and the final command is external and does not clean up zombies it did not start itself. As a workaround you can add a builtin at the end, for example

(sleep 3 & sleep 6; exit $?)

With bash, this does not happen because bash appears to fork always for an external command unless it is the only thing to be run in the process at all. However, this policy results in more process creations than necessary and therefore poorer performance.

POSIX does not appear to say much about whether the shell should allow commands to inherit child processes in this manner. However, a shell is definitely not required to fork as much as bash does.