Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping a killed process

Status
Not open for further replies.

AQWQ

Programmer
Aug 5, 2001
33
IN
Am executing an application thru a shell script say S.sh and the executed application becomes the child of S.sh process.The exact thing i need is if i kill the parent process the child shud get killed automatically.Any idea??

Thanks in advance. Santhosh Ravindran
 
Trapit () # trap function
{
echo "Script aborted!... \c"
echo "Cleaning up... \c"
kill %1
kill -9 $$
}

trap Trapit 1 2 15 # cleanup if script is aborted
# the numbers signify different signals
# don't believe a trap will work if someone
# does a kill -9 against your script

# do your regular code here

# try doing a ctrl-c and see what happens.

# you can modify the actins in the function

# kill %1 would kill the first job
# if you ran a child script in the background.
# kill -9 would kill the parent script.

hope this helps,

RObert Robert G. Jordan

Robert@JORDAN2000.com
Unix Sys Admin
Chicago, Illinois U.S.A.
[lightsaber]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top