1

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?

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.

1
#somecommand has to be a unique substring of the command being run

trap "kill -3 %?somecommand" sigint

somecommand&
wait %?somecommand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.