是否可以忽略所有信号? [英] Is it possible to ignore all signals?

查看:28
本文介绍了是否可以忽略所有信号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个服务器应用程序,我想保护它不被任何我可以忽略的信号阻止.有没有办法一次性忽略所有可能的信号,而不需要一一设置?

I have a server application which I want to protect from being stopped by any signal which I can ignore. Is there a way to ignore all possible signals at once, without setting them one by one?

推荐答案

是:

#include <signal.h>

sigset_t mask;
sigfillset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);

这不会完全忽略信号,而是阻止它们;这在实践中是相同的效果.

This does not exactly ignore the signals, but blocks them; which in practice is the same effect.

我想没有必要提到 SIGKILLSIGSTOP 不能以任何方式被阻止或忽略.

I guess there's no need to mention that SIGKILL and SIGSTOP cannot be blocked nor ignored in any way.

更详细的语义,如掩码继承规则等,查看man页面

For more detailed semantics, like mask inheritance rules and the like, check the man page

这篇关于是否可以忽略所有信号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆