[Tutor] Getting info about processes via pid

Dwyer, Michael Michael.Dwyer at ca.com
Thu Oct 13 20:09:24 CEST 2005


Hi Lawrence,

In a UNIX environment the method used to determine if a process is
running is to issue a "kill -0 pid".  If the process is running the
return value will be zero (0) and -1 with errno set to ESRCH - No
process or process group can be found corresponding to that specified by
pid.

THANX(MKD).

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of lawrence wang
Sent: Thursday, October 13, 2005 10:30 AM
To: tutor at python.org
Subject: [Tutor] Getting info about processes via pid

So I have a list of pids, and I want to check whether the pids still
refer to live processes or not. Currently I'm doing that thus:

pids = ['4550\n', ...]
procs = os.popen("ps ax|grep %s|awk '{ print $1 }'" %
keyword).readlines()

and comparing the two lists. I'm wondering, though, if there's a way
to do this that's less dependent on external programs. I thought
os.waitpid() might work, but on *nix I can only call it for child
processes.

Lawrence Wang
_______________________________________________
Tutor maillist  -  Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list