I've got a C shell script that runs a program. That program spawns off a child. When I send a SIGINT to my shell script via ctrl-C, the shell script exits as well as the process that it spawned I think. However, the last process remains. How can I instruct C shell to kill all child processes before it exits then?
How about creating a signal trap for SIGINT? See the Interrupt Handling section here :
#!/bin/csh
# Setup sigint handler
onintr close
# start a background process
sleep 1000&
setenv pid $!
while (1 == 1)
echo Program is running
sleep 2
end
close:
echo End of program. Kill $pid
kill $pid
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.