title: Why can't a write to disk be interrupted by signal?
body: <p>I read about the signal manual page in signal(7) about "Interruption of system calls and library functions by signal handlers", I wonder what will happen if a signal generated when a write to disk is in the process, so I write a demo to test this kind of situation:</p>
  
  <pre><code>#include &lt;errno.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  
  #define BUFFER_SIZE (1024 * 1024 * 1024)
  char buffer[BUFFER_SIZE] = { 0 };
  void handler(int num)
  {
      char* message = "handler invoked for SIGINT\n";
      if (write(STDOUT_FILENO, message, strlen(message)) &lt; strlen(message)) {
          perror("write to stdout error");
      }
  }
  
  int main(int argc, char* argv[])
  {
      int fd;
      if ((fd = open("tempfile", O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, S_IRWXG | S_IRWXO | S_IRWXU)) &lt; 0) {
          perror("open error");
          return -1;
      }
      struct sigaction siga;
      siga.sa_handler = handler;
      sigaction(SIGINT, &amp;siga, NULL);
      int count;
      while (1) {
          if ((count = write(fd, buffer, BUFFER_SIZE)) &lt; BUFFER_SIZE) {
              printf("write filed with only %d bytes:%s\n", count, strerror(errno));
              break;
          } else {
              printf("write done with %d bytes\n", count);
          }
      }
      close(fd);
      return 0;
  }
  </code></pre>
  
  <p>I found that a write to a disk can't be interrupted by signal which can be proved below:
  <a href="https://i.stack.imgur.com/dy7Nn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dy7Nn.png" alt="enter image description here"></a>
  I was trying to generate SIGINT through Ctrl+C, but write can't be interrupted until it writes all requested bytes to the disk. So, is a write to a disk not interruptable? And why?</p>