Best way to determine if a certain PID is still running
Roy Smith
roy at panix.com
Fri Feb 3 09:00:29 EST 2006
David Hirschfield <davidh at ilm.com> wrote:
> I'm launching a process via an os.spawnvp(os.P_NOWAIT,...) call.
> So now I have the pid of the process, and I want a way to see if that
> process is complete.
>
> I don't want to block on os.waitpid(), I just want a quick way to see if
> the process I started is finished.
On Unix, you can do kill (pid, 0), and if you get back ESRCH, you know the
pid doesn't exist. It is the classic way to ask if a process is running on
Unix. But, there's several problems with that, the biggest one being that
those semantics don't seem to be exposed by phthon's os.kill() method.
> So, should I run a monitor thread which just calls os.waitpid() and when
> the thread indicates via an event that the process completed, I'm golden?
That's what I would do.
More information about the Python-list
mailing list