How can kill all child processes without killing parent process ?

How can kill all child processes without killing parent process ?

Post by Gregor Westemei » Wed, 24 Jul 1996 04:00:00



: 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...
        }

 
 
 

How can kill all child processes without killing parent process ?

Post by David Che » Wed, 24 Jul 1996 04:00:00


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
:-(

 
 
 

1. Parent process also terminating after killing child process in SIGINT

Ok. So, I am killing my child process when I press Ctrl-C. This works great
except for one odd problem. Unless I do something like a cout right before the
kill statement in my sigint_handler func, my parent all terminates immediately
with the message "Terminated" being displayed. Does anyone know any reason for
this?

Thank you,
Chad

2. magic

3. Install of AIX 5L v5.1 on PowerServer 520

4. Child process terminates when parent process killed

5. To use a dot printer as a typewriter

6. how to kill a child process that runs other children processes

7. Need help with chmod command

8. Help: kill sub-process after parent killed

9. killing a parent process also kills childern ?

10. killing a shell script is not killing child processes

11. Can a process kill its child if it's killed -9