[Tutor] Controlling a process and then killing it

Kent Johnson kent_johnson at skillsoft.com
Sun Oct 24 23:45:23 CEST 2004


Python 2.4 has a replacement for popen, the subprocess module, that gives 
access to the pid. There is a reference implementation available which 
presumably runs under Python 2.3. See PEP 324 for details. 
http://www.python.org/peps/pep-0324.html

Kent

At 12:43 PM 10/23/2004 -0500, Hugo González Monteverde wrote:
>Hi Tutors,
>
>Is there any way to get the process id of something you run using popen*???
>
>I'm writing a front end to MPlayer, and I'm lucky that MPlayer lets me 
>send a "quit" command to it... If I did not have this, how could I get the 
>process ID in order to send a SIGTERM later on and (maybe) reap the children??
>
>mystdin, mystdout = os.popen2(myprogram)
>time.sleep (20)
>#I'd like to kill the process here
>
>Is this available as any attribute in  any module? I'm aware of the 
>functions in the sys module, but they will give me info only if the popen 
>call throws an exception...
>
>Hugo
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list