Some questions

Conor P. Cahill cpcahil at virtech.uucp
Fri Jun 29 22:36:26 AEST 1990


In article <1716 at jura.tcom.stc.co.uk> ct at tcom.stc.co.uk (Clive Thomson) writes:
>
>1) The document for the dup call says that it will return the lowest numbered
>   file descriptor not used by the process. With the exception of one line
>   in "The design and implementation of the BSD 4.3 UNIX operating system"
>   (Leffler et al) I have seen no documentation to say open, creat and socket
>   will do the same. Observation of open seems to suggest that the lowest fd
>   is used, but I would like to be sure.

Zillions of unix commands would be broken if open/creat did not return the
lowest file descriptor available.  All of the std{in|out|err} redirection
code requires this behavior.

>3) I am a little confused by the "death of child signal". Is the following
>   correct. If the parent ignores this signal, the kernel will release
>   entries for zombie processes automatically. If the parent uses the default
>   handler, it must wait() for the death of each child, or the child will
>   become a zombie. If the parent invokes its own handler, in this handler
>   a wait should be invoked, otherwise the child will become a zombie. If
>   the parent dies before the children, all children are adopted by the init
>   process, and the programmer need no longer worry about zombie processes.

If you ignore the signal, a child just goes away, never becoming a zombie.
If you default the signal, a child becomes a zombie until you wait for it.
If you catch the signal, a child becomes a zombie until you wait for it, and
you are sent a signal when the child exits (and then should wait on the 
child).

For most cases, a programmer does not need to worry about zombie processes 
unless she is writing a program that will spawn many children, or will be
a long-running program that will spawn children every once in a while.  The
key is the number of children that can be reasonably expected during a 
single iteration of the parent and the life of the parent itself.  

Low numbers of children (< 5 or so) and/or short lived parents (<1hr or so)
normally do not have to worry about zombies. 

The safest thing to do is determine if the child actually has to run 
asyncronously or can the parent just wait for it to finish.  If the parent
can't wait, use a signal handler, otherwise use the wait following the fork
and exec or whereever it is appropriate.

In general, zombies are not a problem for a system (your system will probably
handle Zillions of processes that exit over the next week or so and 99.99999%
of them will become zombies (at least momentarily)).

-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.,
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.questions mailing list