从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.
在bash中,如何将信号处理程序设置为SIG_IGN?
trap "" INT
设置一个空命令“”作为信号处理程序.但是它真的将处理程序设置为SIG_IGN吗?
当bash执行外部命令时,它会将信号陷阱重置为默认值,并保持忽略的忽略信号.因此,重要的是要知道如何在bash中将信号处理程序设置为SIG_IGN,以及将信号处理程序设置为空命令“”是否与将其设置为SIG_IGN相同.
关于如何在bash中设置信号陷阱为SIG_DFL的类似问题.
谢谢.
解决方法:
从the special built-in utility trap
的POSIX文档:
If action is
-
, the shell shall reset each condition to the default value. If action is null (""
), the shell shall ignore each specified condition if it arises. Otherwise, the argument action shall be read and executed by the shell when one of the corresponding conditions arises.
这意味着在陷阱“”INT之后,您的脚本将忽略INT信号,并且您可以使用trap-INT将陷阱重置为默认值.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。