: Hi all UNIX expert,
: I am now writing a shell script to kill all child processes of a
: particular process. I have written the following
: script:
: ps -ef | grep o\\ra | awk '{print $2}' | xargs kill
: where ora is the name of the parent process
: However, this shell script only kills out the parent process,
: Does anyone know how to kill all child process without
: killing that parent process ? Please advise !!! Many thanks !!!
: Have a nice UNIX day !!!
you will have to read all matching processes and only kill the last in the
chain by using PID and PPID; unfortunately we can not assume that the
child is the process with the highest PPID:
assume $2=PID , $3=PPID ( coming from ps -ef | grep o\\ra | grep -v grep )
{
PID[ $2 ]=""
PPID[ $3 ]=""
END{Quote:}
# process ids which are also parents should be deleted
for( pid in PPID ) if ( pid in PID ) delete PID[ pid ]
for( pid in PID ) { do_whatever_you_like_on_your_own_risk( pid ) }
}
function do_whatever_you_like_on_your_own_risk( param ){
code...
}