Want to monitor process..

Peter Hansen peter at engcorp.com
Thu Feb 28 15:39:36 CET 2002


Jonathan Gardner wrote:
> 
> Haeyoung Kim wrote:
> 
> > I want to run or kill a process(program?) using python.
> 
> from os import *
> # Start a process
> ...
> pid = fork()
> if not pid:
>         # I'm a child!
>         exec*(what you want to do)
> # I'm a parent

Whoa!  Don't do that.  I mean the "import *" part 
with the os module.

Module os includes the open() function, and if you
import the namespace that way you'll be masking the
builtin open() function and have all kinds of grief.

Always "import os" and use os.fork(), os.kill() etc.
(Or at least do a "from os import fork, kill".)

-Peter



More information about the Python-list mailing list