Killing A Process By PID

Arvind Singh arvind1.singh at
Fri Sep 21 04:46:27 CEST 2007

 file('/var/lock/Application.lock', 'w').write(str(os.getpid()))
>  Which to be honest appears to run just fine, when I look in that file it
> always contains the correct process ID, for instance, 3419 or something like
> that.
I honestly doubt that. The I/O is buffered and you need to flush()/close()
the file. Otherwise data may not get written until python interpreter exits.

      if file('/proc/%s/cmdline' % pid).read().endswith('python'):
>             os.system('kill %s' % pid)
Are you sure about endswith('python')?
Maybe you need find('python') != -1.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list