How can kill all child processes without killing parent process ? 
Author Message
 How can kill all child processes without killing parent process ?

: 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 ]=""

Quote:
}

END{
# 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...
        }



Sat, 09 Jan 1999 03:00:00 GMT  
 How can kill all child processes without killing parent process ?

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 !!!

Best Regards,

D-Square
:-(



Sat, 09 Jan 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Child process on crashing kills it parent process

2. Killing processes without using 'kill'

3. Thread#kill doesn't kill processes inside a thread

4. Killing all child processes?

5. kill a child-process

6. Tcl process not killing its children on control-c

7. killing child processes

8. Killing of child processes

9. parent-child's child process interaction

10. parent kill his child with VI-server

11. vi server parent kill his child

12. kill a subprocess without killing itself

 

 
Powered by phpBB® Forum Software