Given PID, make sure a process is running on Unix?
Jarkko Torppa
torppa at staff.megabaud.fi
Sat Jul 6 18:43:21 EDT 2002
In article <3D2770A8.7070900 at ob_scure.dk>, Thomas Jensen wrote:
> VanL wrote:
>> Hello,
>>
>> I am trying to get write a python script that on Unix reads a PID from
>> a file and, if that process is still running, exits. If the process is
>> not running, the process would be started.
>>
>> I have everything written except the part that makes sure the process is
>> running. I have poked through the os module, but I can only seem to
>> find information about the current process or child processes, not just
>> some arbitrary process.
>
> If your system has a 'proc' device, you could do something like this:
> os.path.isdir('/proc/%d' % pid)
> Most Unix flavours have a proc device AFAIK.
All(?) unix flawors have kill(2)
>>> import os
>>> os.kill(12331,0)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OSError: [Errno 3] No such process
>>> os.kill(os.getpid(),0)
>>>
--
Jarkko Torppa, Elisa Internet
More information about the Python-list
mailing list