Hi, bpteoh.
Try the following bash script:
Code:
#!/bin/bash
# file: listchild.sh
# Usage: listchild.sh PID
#set -x
: ${start:=$1}
while [ -n "$start" ];
do
echo $start;
# replace spaces/newlines by commas
start=`echo "$start"| tr '\n' ' ' |sed 's/ \+/,/g'`;
# eat up leading comma
start=${start:0:((${#start}-1))};
start=`pgrep -P$start`;
done
Uncomment 'set -x' line to see how the script works. Command `pgrep -P<comma-separated-list-of-pids>' will print newline-separated list of pids, whose parents were listed. On Debian system pgrep can be found in the procps package.
Command `ps -Af --forest` may be useful for checking the result.
To kill all child processes of given one, type:
Code:
kill `./listchild.sh PID`