I have a Linux application, written in C++, which traps the SIGINT interrupt in order to do some final cleanup before exiting. I call this application within a bash script. Now, when I type control-C with the bash script running in the foreground, the script terminates as does the program it invoked but without running the final cleanup code. How can I have the interrupt pass through the bash script, directly to the application, resulting in the final cleanup and then a normal exit which then causes the script itself to exit?
Asked
Active
Viewed 1,056 times
2 Answers
1
bash also has the ability to trap SIGINT. It would be feasible to trap the signal so the script doesn't die, and then in the trap handler, use kill to pass the signal off to your application.
Karu
- 4,922
1
#somecommand has to be a unique substring of the command being run
trap "kill -3 %?somecommand" sigint
somecommand&
wait %?somecommand
infixed
- 819