Getting a proccesses ID
Micah Mayo
astrophels at yahoo.com
Fri Sep 6 11:05:20 EDT 2002
Hi,
I'm writing a little tool for SysAdmins on FreeBSD - I'm trying to make
it as portable as possible(as far as the unices go), and have come upon
a problem - one of the things this tool does is restarts various deamons
on the system, in order to do that I have to send a killsignal to the
pid. The problem is getting the process id - right now I've got a hack
using ps, grep, and awk, which I doubt will translate well to other
flavors of *nix because they all seem to have their own method of
delivering info via ps. Can anyone tell me a cross platform way of
grabbing a particular processes ID
Here's what I'm doing now, by the way:
pid = os.popen("ps -x | grep sshd | grep -v grep | awk '{ print $1 }'")
pid = pid.atoi()
More information about the Python-list
mailing list