Getting a proccesses ID

Micah Mayo astrophels at
Fri Sep 6 12:48:40 EDT 2002

Sean 'Shaleh' Perry wrote:
> On Friday 06 September 2002 08:05, Micah Mayo wrote:
>>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()
>>>>import os
> 29421
> (-:
Ah, but os.getpid get's my pid, I need to get another programs, and in 
fact, several other program's pid. :)


More information about the Python-list mailing list