1755691 Members
3332 Online
108837 Solutions
New Discussion юеВ

Killing parent pid

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: Killing parent pid

Hi Srini:

> ...replace echo with kill

And while we are on the subject of killing processes, don't use 'kill -9' without first attempting a simple 'kill' first.

A 'kill -9' cannot be caught and thus a process has no (programatic) chance to cleanup temporary files and/or shared memory segments.

Instead, escalate your annihilation:

kill -TERM ${mypid} > /dev/null 2>&1
sleep 2
kill -HUP ${mypid} > /dev/null 2>&1
sleep 2
kill -9 ${mypid} > /dev/null 2>&1

If the first 'kill' works ${mypid} will no longer be valid and the second (and third) 'kill's will be no-ops. If the 'kill -9' fails to terminate the process then it is waiting on an I/O to complete or in some other kernel state for which it can't be interrupted.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: Killing parent pid

Srinikalyan,

>Is there any script to find all the child processes if we give the input as the parent pid?

Which version of OS you are using.
If you are on 11.31 use , ptree , it is a very nice program. It prints the complete process tree hierarchy.

http://docs.hp.com/en/B2355-60130/ptree.1.html


Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Dennis Handly
Acclaimed Contributor

Re: Killing parent pid

>Bill: grep -- -u Be sure to use two dashes (grep --) to terminate the option processing and treat "-u" as a simple string.

Using "--" is overkill and not as flexible as just "-e -u". After -e, you can add more options.

>do NOT grep for pid or ppid!!! This will find critical processes that happen to have matching numbers in the run string.

My grep pattern anchored it to the PPID.