1

Assume that a linux process is trying to read() data from a socket and is blocked on socked fd. What happens to this when it is interrupted by a signal ? Will it return with errno EINRPT or continue to read() on socket fd ?

Is there any generic rule that applies to all the system calls on reception of signals ?

Anil Kumar K K
  • 1,395
  • 1
  • 16
  • 27
  • [man 7 signal](http://man7.org/linux/man-pages/man7/signal.7.html). Section: "Interruption of system calls and library functions by signal handlers". – kaylum Sep 27 '15 at 20:47
  • And there are also similar questions/answers on SO. http://stackoverflow.com/questions/8049756/when-and-how-are-system-calls-interrupted – kaylum Sep 27 '15 at 20:51

1 Answers1

3

In the specific case of sockets, read(2) is considered to be a slow syscall because it can block forever; therefore if a signal is received for which a signal handler has been set up, one of two things can happen:

  1. If the signal handler was set with the SA_RESTART flag in the sa_flags field of struct sigaction, then the syscall is automatically restarted after (and if) the handler returns (cases where the handler does not return include, but are not limited to, handler code that calls exit(3) or uses longjmp(3) / setjmp(3)); user code does not see EINTR in this case.
  2. If the SA_RESTART flag was not set, the syscall returns prematurely and errno is set to EINTR.

For the generic rules, see man 7 signal, pay particular attention to the section Interruption of system calls and library functions by signal handlers

Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70