Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40957
  • 博文数量: 14
  • 博客积分: 630
  • 博客等级: 上士
  • 技术积分: 130
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-05 10:59
文章分类

全部博文(14)

文章存档

2011年(1)

2009年(13)

我的朋友
最近访客

分类: LINUX

2009-02-17 17:09:00

Interruption of System Calls and Library Functions by Signal Handlers

If a signal handler is invoked while a system call or library function call is blocked, then either:

  • the call is automatically restarted after the signal handler returns; or

  • the call fails with the error EINTR.

Which of these two behaviors occurs depends on the interface and whether or not the signal handler was established using the SA_RESTART flag (see ). The details vary across Unix systems; below, the details for Linux.

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:

  • , , , , and calls on "slow" devices. A "slow" device is one where the I/O call may block for an indefinite time, for example, a terminal, pipe, or socket. (A disk is not a slow device according to this definition.) If an I/O call on a slow device has already transferred some data by the time it is interrupted by a signal handler, then the call will return a success status (normally, the number of bytes transferred).

  • , if it can block (e.g., when opening a FIFO; see ).

  • , , , , and .

  • Socket interfaces: , , , , , , , and , unless a timeout has been set on the socket (see below).

  • File locking interfaces: and F_SETLKW.

  • POSIX message queue interfaces: , , , and .

  • FUTEX_WAIT (since Linux 2.6.22; beforehand, always failed with EINTR).

  • POSIX semaphore interfaces: and (since Linux 2.6.22; beforehand, always failed with EINTR).

The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR when interrupted by a signal handler:

  • Socket interfaces, when a timeout has been set on the socket using : , , , and , if a receive timeout (SO_RCVTIMEO) has been set; , , , and , if a send timeout (SO_SNDTIMEO) has been set.

  • Interfaces used to wait for signals: , , , and .

  • File descriptor multiplexing interfaces: , , , , , and .

  • System V IPC interfaces: , , , and .

  • Sleep interfaces: , , and .

  • from an file descriptor.

  • .

The function is also never restarted if interrupted by a handler, but gives a success return: the number of seconds remaining to sleep.

写traceroute时遇到的问题,在线程里调用recvfrom,由alarm定时,却没有recvfrom并没有被alarm中断,找了好一下,终于找到上边的解释。
继续学习。。。



阅读(786) | 评论(0) | 转发(0) |
0

上一篇:linux 信号通信总结

下一篇:recvfrom 注意点

给主人留下些什么吧!~~