Pass SIGINT through bash script to application

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?

sizzzzlerz

Posted 2016-03-12T01:06:32.203

Reputation: 141

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.

Mikey T.K.

Posted 2016-03-12T01:06:32.203

Reputation: 3 224

1

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

trap "kill -3 %?somecommand" sigint

somecommand&
wait %?somecommand

infixed

Posted 2016-03-12T01:06:32.203

Reputation: 759