Brian Schlenker
Brian Schlenker

Reputation: 5426

Determine which signal caused EINTR?

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.

Upvotes: 5

Views: 2157

Answers (1)

Stian Skjelstad
Stian Skjelstad

Reputation: 2335

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

Upvotes: 1

Related Questions