epoll_wait fails due to EINTR, how to remedy this?

Deadly 提交于 2020-01-02 08:48:18

问题


My epoll_wait fails due to EINTR. My gdb trace shows this:

enter code here
221     in ../nptl/sysdeps/pthread/createthread.c
(gdb) 
224     in ../nptl/sysdeps/pthread/createthread.c
(gdb) 
 [New Thread 0x40988490 (LWP 3589)]

227     in ../nptl/sysdeps/pthread/createthread.c
(gdb) 
epoll_wait error in start timer: Measurement will befor entire duration of execution
epoll_wait: Interrupted system call
[Thread 0x40988490 (LWP 3589) exited]

This string "epoll_wait error in start timer: Measurement will befor entire duration of execution" is printed by me in stderr.

I am not able to make out, how to remedy this EINTR so that epoll_wait can work. Any idea how this EINTR is generated by GDB trace?


回答1:


Certain signal handler will interrupt epoll_wait(), select() and similar system calls on any Unix or Linux. This is by design so you can interrupt these system calls.

You cannot directly remedy it. The typical solution is to explicitly check the errno for EINTR and to execute epoll_wait() again:

int nr;
do {
    nr = epoll_wait(epfd, events, maxevents, timeout);
} while (nr < 0 && errno == EINTR);

Also see: gdb error: Unable to execute epoll_wait: (4) Interrupted system call



来源:https://stackoverflow.com/questions/6870158/epoll-wait-fails-due-to-eintr-how-to-remedy-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!