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.
我们如何在 shell 脚本中捕获信号,我们可以在哪里捕获信号?
也有人可以解释
# trap commands signals
您可以编写一个 shell 脚本:
trap ctl_c INT # trap <name_of_function_to_called> <Signal to be handled> function ctl_c(){ // signal handling logic needed. }
现在,每当您发送 SIGINT(按键 CTRL + C)时,都会调用此函数,而不是默认功能。