什么时候检查EINTR并重复函数调用? [英] When to check for EINTR and repeat the function call?

查看:70
本文介绍了什么时候检查EINTR并重复函数调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为嵌入式Linux系统编写用户应用程序,并且正在使用设备的通用功能,例如打开,关闭,读取,ioctl等.现在,我读到有关EINTR的信息,表明该功能已被信号中断,但我不确定其中的含义.在我拥有的所有示例程序中,有时都会完成例如ioctl(),有时未完成,例如读().所以,我有点困惑.

I am programming a user application for a embedded Linux system, and I am using the common functions such as open, close, read, ioctl, etc. for the devices. Now, I read about EINTR, indicates that the function was interrupted by a signal, but I am not sure about the implications. In all the example programs I have, sometimes it is done, e.g. ioctl(), sometimes it is not done, e.g. read(). So, I am a little bit confused.

我最好何时检查EINTR并重复函数调用?

When do I preferably check for EINTR and repeat the function call?

推荐答案

请参阅sigaction: http://pubs.opengroup.org/onlinepubs/009695399/functions/sigaction.html

See sigaction : http://pubs.opengroup.org/onlinepubs/009695399/functions/sigaction.html

SA_RESTART
  This flag affects the behavior of interruptible functions; that is, those 
  specified to fail with errno set to EINTR. If set, and a function specified 
  as interruptible is interrupted by this signal, the function shall restart 
  and shall not fail with EINTR unless otherwise specified. If the flag is not 
  set, interruptible functions interrupted by this signal shall fail with errno 
  set to EINTR.

默认情况下,您具有SA_RESTART行为,因此,如果您不使用信号,则不必担心EINTR.

By default, you have the SA_RESTART behavior, so you don't have to worry about EINTR, if you don't play with signals.

这篇关于什么时候检查EINTR并重复函数调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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