getpid Usage

Jeff Blaine jblaine at kickflop.ne.mediaone.net
Thu Jul 13 21:44:51 EDT 2000


In article <8kksms+n5h5 at eGroups.com>, david at tumbleweed.com wrote:
>Is there some convenient way of getting os.getpid to return the PID of
>a given executable? What I want to do is start a process and know it's
>PID. When I do the following I get the PID of the python executable.
>
>os.system("path")
>os.getpid()
>
>Alternatively, as a hack, I am doing:
>os.system(self.m_server_start_exe)
>for line in os.popen("ps -ef | grep -i IMEController | awk '{ if (NR >
>1) { print $2 }}'").readlines():
>            pid = line[:-1]
>
>I would rather just path in an executable name/pathname and have it
>return this process' pid. Is there an updated version of os.getpid I
>could use to do this. If not, is there a better solution that is not
>shell dependent?

Unless someone has an answer to this (I don't know of one),
if you have the source to the thing you are spawning, I recommend
writing out a PID file as part of that program (/tmp/my.pid,
whatever).



More information about the Python-list mailing list