killing all subprocess childrens
Chris Rebert
clp2 at rebertia.com
Thu Sep 2 18:24:17 EDT 2010
On Thu, Sep 2, 2010 at 12:58 PM, Aahz <aahz at pythoncraft.com> wrote:
> In article <mailman.353.1283398245.29448.python-list at python.org>,
> Astan Chee <astan.chee at al.com.au> wrote:
>>Chris Rebert wrote:
>>>
>>> import os
>>> import psutil # http://code.google.com/p/psutil/
>>>
>>> # your piece of code goes here
>>>
>>> myself = os.getpid()
>>> for proc in psutil.process_iter():
>>
>>Is there a way to do this without psutil or installing any external
>>modules or doing it from python2.5?
>
> Lightly edited code I wrote yesterday:
>
> cmd = ['ps', '-eo', 'pid,ppid']
> output = Popen(cmd, stdout=PIPE).communicate()[0]
> output = output.split('\n')[1:] # skip the header
> for row in output:
> if not row:
> continue
> child_pid, parent_pid = row.split()
> if parent_pid == str(pid):
> child_pid = int(child_pid)
> os.kill(child_pid, signal.SIGUSR1)
Although this doesn't meet the OP's Windows-compatibility requirement.
Cheers,
Chris
More information about the Python-list
mailing list