Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
看起来像
trap on_sigint SIGINT
只要SIGINT被捕获就停止脚本。然后,on_sigint被执行。是否可以在SIGINT不停止脚本的情况下进行处理?
SIGINT
on_sigint
SIGINT处理程序运行后不会终止脚本。这是一个小型的、自包含的测试用例:
trap on_sigint SIGINT on_sigint() { echo "caught"; } { sleep 3; kill -SIGINT $$; } & echo "Waiting for sigint" sleep 5 echo "Still running"
输出是:
Waiting for sigint caught Still running
如果您的观察是正确的,那么最后一行就不会出现。