How to tell if a forked process is done?

François Pinard pinard at iro.umontreal.ca
Wed Sep 24 09:52:45 EDT 2003


[Klaus Alexander Seistrup]
> François Pinard wrote:
> 
> > In the less usual case you want concurrency between Python and the
> > forked shell command,  for only later checking if the forked process
> > is done, the usual way is to send a zero signal to the child using
> > `os.kill()'.  The zero signal would not do any damage in case your
> > forked process is still running.  But if the process does not exist,
> > the parent will get an exception for the `os.kill()', which you may
> > intercept.  So you know if the child is running or finished.
> 
> This will yield a false positive and potential damage if the OS has
> spawned another process with the same pid, and running under your uid,
> as the task you wanted to supervise.

Granted in theory, yet this does not seem to be considered a real
problem in practice.  To generate another process with the same pid, the
system would need to generate so many intermediate processes that the
process counter would overflow and come back to its current value.  The
`kill(pid, 0)' trick is still the way people seem to do it.

Do you know anything reasonably simple, safer, and that does the job?

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard





More information about the Python-list mailing list