forking and zombies in SYSV.
leland.f.derbenwick
lfd at cbnewsm.att.com
Tue Aug 28 03:04:58 AEST 1990
In article <5980067 at hpfcdc.HP.COM>, rml at hpfcdc.HP.COM (Bob Lenk) writes:
> Several people have suggested
>
> signal(SIGCLD, SIG_IGN);
>
> While this does prevent zombies from being formed in System III, System
> V, and compatible systems, there are some reasons to avoid it:
>
> 1) Portability. This does not work in all implementations
> (notably not in BSD). It is not required by POSIX, XPG,
> or even the SVID.
This behavior _is_ required by the SVID: see "signal(BA_OS)" on
page 6-124 of Volume 1 of the Third Edition (8/89):
If the diposition for SIGCHLD is set to SIG_IGN, the calling
process's child processes will not create zombie processes
when they terminate [see exit(BA_OS)]. If the calling process
subsequently waits for its children, it will block until all
of its children terminate; it will then return a value of -1
with errno set to ECHILD ...
> 2) Possible side-effects. This can impact any part of your
> program that creates children, including library calls that
> might create children for reasons unknown to you. It can
> impact the programs exec'd by descendents if they create
> children. Most code that creates children expects to wait
> for them. This can cause such code to hang (until all your
> children have died) and/or to get unexpected errors (possibly
> missing out on important status information).
This is correct, but it would be simple to add
signal(SIGCHLD, SIG_DFL);
to the child processes (in main() if they are invoked via "system",
or just after the fork() if the fork()/exec() is done explicitly).
-- Speaking strictly for myself,
-- Lee Derbenwick, AT&T Bell Laboratories, Warren, NJ
-- lfd at cbnewsm.ATT.COM or <wherever>!att!cbnewsm!lfd
More information about the Comp.unix.wizards
mailing list