2018-12-07 20:12:53 UTC
Sometimes, the trapped code (e.g., for clean-up) takes time to run. If
the trap is not disabled, the clean-up code may not get finished if a
2nd signal comes.
I'm wondering what is the recommended practice to program for traps. I
come up with the following to always reset the trap at the beginning
so that I will not respond to new traps until the clean up code in the
original trap is finished. Is this appropriate? Thanks.
# vim: set noexpandtab tabstop=2:
trap 'echo SIGINT start; trap "" SIGINT; sleep 10; echo SIGINT end' SIGINT
^Cecho SIGINT start; trap "" SIGINT; sleep 10; echo SIGINT end