From https://unix.stackexchange.com/a/447032/674
So in terms of code, assuming the
SIGINT
signal, these are the three options:
signal(SIGINT, SIG_IGN);
to ignore- To not call the
signal()
function, or to call it withsignal(SIGINT, SIG_DFL);
and thus to let the default action occur, i.e. to terminate the processsignal(SIGINT, termination_handler);
, wheretermination_handler()
is a function that is called the first time the signal occurs.
In bash, how can I set up the handler of a signal to be SIG_IGN
?
trap "" INT
sets an empty command ""
as the signal handler. But does it really set the handler to SIG_IGN
?
When bash executes an external command, it will reset signal traps to default, and keep ignored signals still ignored. So it is important to know how to set up a signal handler to be SIG_IGN
in bash, and whether setting a signal handler to the empty command ""
is the same as setting it to SIG_IGN
.
Similar question for how to set up a signal trap to be SIG_DFL
in bash.
Thanks.