如何避免由于Linux中的信号而导致睡眠呼叫中断? [英] How to avoid the interruption of sleep calls due to a signal in Linux?

查看:145
本文介绍了如何避免由于Linux中的信号而导致睡眠呼叫中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux中使用实时信号来通知新数据在串行端口中的到达.不幸的是,这会导致有信号时睡眠呼叫被中断.

I'm using a real time signal in Linux to be notified of the arrival of new data in a serial port. Unfortunately this causes sleep calls to be interrupted when there is signal.

有人知道避免这种行为的方法吗?

Does anybody know of a way to avoid this behavior?

我尝试使用常规信号(SIGUSR1),但仍保持相同的行为.

I tried using a regular signal (SIGUSR1) but I keep getting the same behavior.

推荐答案

来自nanosleep联机帮助页:

From the nanosleep manpage:

nanosleep至少在* req中指定的时间延迟程序的执行.如果已将信号传递到进程,则该函数可以更早返回.在这种情况下,除非rem为NULL,否则它将返回-1,将errno设置为EINTR,并将剩余时间写入rem指向的结构中.然后,可以使用* rem的值再次调用nanosleep并完成指定的暂停.

nanosleep delays the execution of the program for at least the time specified in *req. The function can return earlier if a signal has been delivered to the process. In this case, it returns -1, sets errno to EINTR, and writes the remaining time into the structure pointed to by rem unless rem is NULL. The value of *rem can then be used to call nanosleep again and complete the specified pause.

这篇关于如何避免由于Linux中的信号而导致睡眠呼叫中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆