I want to handle if epoll_wait
was interrupted by any reason (for example by SIGINT)
while ( true ) {
n = epoll_wait ( epoll_fd, events, max_events, -1 );
if ( errno == EINTR ) {
...
}
}
But debugger did not even go to if
. Program was terminated in epoll_wait
. I've added some magick:
signal ( SIGINT, placebo );
while ( true ) {
n = epoll_wait ( epoll_fd, events, max_events, -1 );
if ( errno == EINTR ) {
...
}
}
And all works as expected. But this is ugly. What is the right way to let me handle any epoll_wait
's interrupt?
You need to either handle signals or block them. If you just want to ignore EINTR I suggest blocking via the sigprocmask() or signal(signum, SIG_IGN) for a single-threaded process, or via pthread_sigmask() for a multithreaded process. If you want to actually do something, use sigaction() to install a handler.
Do not use signal() to set an actual handler. Its behavior varies across UNIX platforms. Read the manpages for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.