title: Why isn't write(2) returning EINTR?
body: <p>I've been reading about <code>EINTR</code> on <code>write(2)</code> etc, and trying to determine whether I need to check for it in my program. As a sanity check, I tried to write a program that would run into it. The program loops forever, writing repeatedly to a file.</p>
  
  <p>Then, in a separate shell, I run: </p>
  
  <pre><code>while true; do pkill -HUP test; done
  </code></pre>
  
  <p>However, the only output I see from test.c is the <code>.</code>s from the signal handler. Why isn't the <code>SIGHUP</code> causing <code>write(2)</code> to fail?</p>
  
  <p>test.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  
  #include &lt;sys/types.h&gt;
  
  void hup_handler(int sig)
  {
      printf(".");
      fflush(stdout);
  }
  
  int main()
  {
      struct sigaction act;
      act.sa_handler = hup_handler;
      act.sa_flags = 0;
      sigemptyset(&amp;act.sa_mask);
  
      sigaction(SIGHUP, &amp;act, NULL);
  
      int fd = open("testfile", O_WRONLY);
  
      char* buf = malloc(1024*1024*128);
  
      for (;;)
      {
          if (lseek(fd, 0, SEEK_SET) == -1)
          {
              printf("lseek failed: %s\n", strerror(errno));
          }
          if (write(fd, buf, sizeof(buf)) != sizeof(buf))
          {
              printf("write failed: %s\n", strerror(errno));
          }
      }
  }
  </code></pre>