killing all subprocess childrens

Aahz aahz at pythoncraft.com
Thu Sep 2 21:58:49 CEST 2010


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)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"...if I were on life-support, I'd rather have it run by a Gameboy than a
Windows box."  --Cliff Wells



More information about the Python-list mailing list