分类: LINUX
2009-02-17 17:09:00
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中断,找了好一下,终于找到上边的解释。