Controlling processes from Python

Posted by Nathan on Stack Overflow See other posts from Stack Overflow or by Nathan
Published on 2010-06-02T21:17:21Z Indexed on 2010/06/02 21:24 UTC
Read the original article Hit count: 167

Filed under:
|

Hi,

I want to control several subprocesses of the same type from python (I am under linux). I want to:

  • Start them.
  • Stop them.
  • Ask if they are still running.

I can start a processes with with spawnl, and get the pid. Using this pid I can stop it with kill. And I am sure there is also a way to ask if it is running with the pid.

The problem is, what if the following happens: I start a process, remember the pid. The process ends without me noticing and another completely different process starts getting assigned the same pid. I attempt to kill my process, I kill a completely different one.

What is the better way to start and control processes in python? Thanks!

© Stack Overflow or respective owner

Related posts about python

Related posts about pid