Getting a proccesses ID

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Sep 6 11:30:11 EDT 2002


On Friday 06 September 2002 08:05, Micah Mayo wrote:
> 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()

>>> import os
>>> os.getpid()
29421

(-:




More information about the Python-list mailing list