Determine which signal caused EINTR?

2019-05-04 16:17发布

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.

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.

1条回答
狗以群分
2楼-- · 2019-05-04 16:47

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

查看更多
登录 后发表回答