如何避免睡眠通话中断,由于在Linux中的信号 [英] How to avoid the interruption of sleep calls due to a signal in Linux

查看:112
本文介绍了如何避免睡眠通话中断,由于在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指定的时间执行。如果信号已交付过程中的作用可以提早返回。在这种情况下,返回-1,设置errno为EINTR,并写入到结构指向雷姆,除非REM是NULL的剩余时间。 * 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天全站免登陆