Best way to determine if a certain PID is still running
Thomas Guettler
niemand.leermann at thomas-guettler.de
Fri Feb 3 10:32:55 EST 2006
Am Thu, 02 Feb 2006 17:10:24 -0800 schrieb David Hirschfield:
> 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. I could popen("ps -p %d" % pid) and
> see whether it's there anymore...but since pids get reused, there's the
> chance (however remote) that I'd get a false positive, plus I don't
> really like the idea of calling something non-pure-python to find out.
Hi,
at least on linux you can test this:
os.path.exists("/proc/%d" % mypid)
If you want to be sure that the pid is not reused, you
can look at: /proc/PID/cmdline
Maybe you can read the parent-pid in the proc directory. This should be
the pid if your script.
HTH,
Thomas
--
Thomas Güttler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
Spam Catcher: niemand.leermann at thomas-guettler.de
More information about the Python-list
mailing list