c ++:确定哪个信号引起EINTR? [英] c++: Determine which signal caused EINTR?

查看:228
本文介绍了c ++:确定哪个信号引起EINTR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行epoll循环,有时我调用epoll_wait返回-1,并将errno设置为EINTR。有时候,我想要结束epoll循环,就像SIGTERM或SIGINT的情况一样。但我有这个代码用-pg标志编译,所以定期SIGPROF(27)信号被提出,停止我的循环。

I am running an epoll loop and sometimes my call to epoll_wait returns -1 with errno set to EINTR. Sometimes, I want this to end the epoll loop, like in the case of SIGTERM or SIGINT. But I have this code compiled with the -pg flag, so periodic SIGPROF (27) signals are raised that stop my loop.

所以...是否可以打开signum,以便我可以确定何时退出或继续?

So... is it possible to switch on the signum so that I can determine when to exit vs. continue? I would like to avoid anything that employs the use of a global to keep track of the most recent signal fired.

推荐答案

添加信号时,我想避免使用全局变量来跟踪最近发出的信号。处理程序在SIGTERM和SIGINT。在这些处理程序中,你设置一个变量,你检查你的主epoll循环

Add signal handlers on SIGTERM and SIGINT. Inside those handlers you set a variable that you check in your main epoll loop

这篇关于c ++:确定哪个信号引起EINTR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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