Newbie - Process Management
chris.gonnerman at newcenturycomputers.net
Tue Jun 18 14:08:03 CEST 2002
----- Original Message -----
From: "Dan Scholey" <scholeyd at logica.com>
> I am hoping you can help me, I am fairly new to python (and Unix) but am
> trying to solve the following problem...
> I want to be able to check if a parent process has died.
> At the moment I can check that a child process has died using...
> status = (os.waitpid(child, os.WNOHANG))
> if status!=0:
> I've looked at several manuals and can't find a similar function for
> Obviously I know both the parent and child process id ( get_pid() /
> get_ppid() ).
Here is a partial screen-capture from my Linux system. If you are using any
standard Unixoid OS this should work:
<< partial ps listing >>
15321 pts/1 S 0:00 -bash
15377 ? S 0:00 /usr/sbin/httpd -f /etc/httpd/httpd.conf
15521 pts/1 R 0:00 ps ax
office:~ $ python
Python 2.1.2 (#1, Jan 16 2002, 17:04:23)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "copyright", "credits" or "license" for more information.
>>> import os
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 3] No such process
In other words, PID 15321 exists (I knew it did, it's my shell) but 15322
> I have a workaround of....
> ps_line=string.split(commands.getoutput("ps -lp
> if string.atoi(string.split(ps_line))!=daddy:
> ... but I would rather not use ps.
> Any ideas?
Hope this helps.
Chris Gonnerman -- chris.gonnerman at newcenturycomputers.net
More information about the Python-list