I noticed a small error:
The trick here is to reset the signal handler to its OS default after receiving the first signal. The default for many signals, including
SIGTERM(the one coming from
CTRL+C) is to terminate the program.
Right, thanks, fixed (nevertheless, one usually wants to handle all of SIGTERM, SIGINT and SIGQUIT together).