title: When and how are system calls interrupted?
body: <p>This is a followup question to <a href="https://stackoverflow.com/questions/8041171/is-a-successful-send-atomic/8041309">Is a successful send() &quot;atomic&quot;?</a>, as I think it actually concerns system calls in general, not just sends on sockets.</p>
  
  <p>Which system calls can be interrupted, and when they are, where is the interruption handled? I've learned about SA_RESTART, but don't exactly understand what is going on.</p>
  
  <ul>
  <li><p>If I make a system call without SA_RESTART, can the call be interrupted by any kind of interrupts (e.g. user input) that don't concern my application, but require the OS to abort my call and do something else? Or is it only interrupted by signals that directly concern my process (CTRL+C, socket closed, ...)?</p></li>
  <li><p>When setting SA_RESTART, what are the semantics of a send() or any other "slow" syscall? Will it always block until all of my data is transmitted or the socket goes down, or can it return with a number smaller than the count in send()'s parameter?</p></li>
  <li><p>Where is restarting implemented? Does the OS know that I want the call to be restarted upon any interrupts, or is some signal sent to my process and then handled by library code? Or do I have to do it myself, e.g. wrap the call in a while loop and retry as often as necessary?</p></li>
  </ul>