killing all subprocess childrens

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

In article <mailman.353.1283398245.29448.python-list at>,
Astan Chee  <astan.chee at> wrote:
>Chris Rebert wrote:
>> import os
>> import 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:
            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           <*>

"...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