c - epoll_wait 由于 EINTR 而失败,如何补救?

标签 c linux system-calls epoll interrupted-exception

由于 EINTR,我的 epoll_wait 失败了。我的 gdb 跟踪显示:

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]

这个字符串“启动计时器中的 epoll_wait 错误:测量将在整个执行期间进行”是我在 stderr 中打印的。

我不知道如何补救这个 EINTR 以便 epoll_wait 可以工作。知道这个 EINTR 是如何由 GDB 跟踪生成的吗?

最佳答案

某些信号处理程序将中断 epoll_wait()select() 以及任何 Unix 或 Linux 上的类似系统调用。这是设计使然,因此您可以中断这些系统调用。

您不能直接补救它。典型的解决方案是显式检查 EINTR 的错误号并再次执行 epoll_wait():

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

另见:gdb error: Unable to execute epoll_wait: (4) Interrupted system call

关于c - epoll_wait 由于 EINTR 而失败,如何补救?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6870158/

相关文章:

python - 使用 python 在 linux 中更改背光亮度

c - 如何重新启动计时器?

c++ - OpenCV Mat 在 push_back 时崩溃

linux - 如何将端口 8081 定向到子文件夹

mysql - 使用 lampp 托管时如何修复 "Slim Application Error"错误

linux - 根据读取请求写入文件 - Linux

windows - 调用 GetExtendedTcpTable () 时出现空响应

c++ - volatile 变量在一个客户线程和一个生产者线程中安全吗?

c++ - 为什么偏爱数据结构对齐?

c - 在字符串中查找前缀作为后缀