How to tell if a forked process is done?

Donn Cave donn at u.washington.edu
Thu Sep 25 18:22:08 CEST 2003


In article <3F722887.F4521F68 at alcyone.com>,
 Erik Max Francis <max at alcyone.com> wrote:

> Klaus Alexander Seistrup wrote:
> 
> > Anyway you look at it, killing blindly is bad programming practice.
> 
> But he's killing with a signal of 0.  From kill(2):
> 
>        If sig is 0, then no signal is sent, but error checking is
>        still performed.
> 
> It's perfectly reasonable behavior to kill a process with a 0 signal; it
> does no harm.

I think it would be reasonable to posit an implied context
for discussion of any programming technique, that said
technique would be deployed for some purpose.

If that is not too bold of an assumption, I think it follows
that our standard for a good programming practice has to be
a little more stringent that just whether deployment of the
technique causes any harm.  In this case, for example, the
proposed technique is use the information returned from kill(0)
to decide whether some process is still alive, and according
to our theory of purposeful programming, we may guess that
the program then acts on the basis of that decision.

If kill(0) actually does not reliably indicate that the process
is alive because process IDs are not unique over time, then
it is arguably harmful as a programming practice even if it
is harmless as a system call.

What actually happens with processes that exited but haven't
been reaped by their parent with wait(2) or similar?  Seems
to vary quite a bit, here's what I found -

 FreeBSD 5.1   - No such process, ps PID=0, owned by me
 Linux 2.4     - kill -0 works
 MacOS X/Darwin - No such process, ps original PID, owner root

   Donn Cave, donn at u.washington.edu




More information about the Python-list mailing list