如何知道,如果一个Linux系统调用重新启动或没有? [英] How to know if a Linux system call is restartable or not?

查看:140
本文介绍了如何知道,如果一个Linux系统调用重新启动或没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有些系统调用可以通过内核透明地重新启动,如果在安装信号处理程序时,使用了 SA_RESTART 标记,根据人的signal(7)​​

Some system calls can be restarted transparently by the Kernel if the SA_RESTART flag is used when installing the signal handler, according to man signal(7):

如果下列接口中的一个阻塞调用中断
  通过信号处理程序,,然后呼叫将自动重新启动
  信号后,
         如果使用了SA_RESTART标志处理程序返回
;否则调用将失败,出现错误EINTR:

If a blocked call to one of the following interfaces is interrupted by a signal handler, then the call will be automatically restarted after the signal handler returns if the SA_RESTART flag was used; otherwise the call will fail with the error EINTR:

然后提到,可以(也不能)重新启动一些系统调用,但没有提到的close()在任何地方,我怎么会知道,如果的close()或其它任何功能,可重新启动或没有?确实 POSIX 指定它或者是特定的Linux行为?我在哪里可以找到更多信息?

Then it mentions some system calls that can (and can not) be restarted, but does not mention close() in either places, how would I know if close(), or any other function, is restartable or not ? does POSIX specify it or is it a Linux-specific behaviour ? where can I find more info ?

推荐答案

根据 POSIX.1-2008 ,在 SA_RESTART 标志适用于所有的中断功能(这是记录失败, EINTR 所有功能)

As per POSIX.1-2008, the SA_RESTART flag applies to all interruptible functions (all function which are documented to fail with EINTR):

SA_RESTART

SA_RESTART

这标志影响的中断功能的行为;也就是说,这些指定的失败,并将errno设置为[EINTR]。如果置位,并指定为可中断的函数由该信号中断,则功能必须重新启动,除非另有说明,不得以[EINTR]失败。如果重新启动,它使用了超时可中断的功能,重新启动后的超时的持续时间被设定为不超过原超时值未指定的值。如果没有设置标志,这个信号中断中断功能应失败,并将errno设置为[EINTR]。

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 an interruptible function which uses a timeout is restarted, the duration of the timeout following the restart is set to an unspecified value that does not exceed the original timeout value. If the flag is not set, interruptible functions interrupted by this signal shall fail with errno set to [EINTR].

也就是说,这是没有重新启动功能列表是Linux的特定的(而且可能算作一个错误)。

That is, the list of functions which are not restarted is Linux-specific (and probably counts as a bug).

这篇关于如何知道,如果一个Linux系统调用重新启动或没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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