title: C language & sigintHandler
body: <p>I want to delete the FIFO file when I suddenly click "ctrl+c"  . I want to catch that signal and then delete the after before actually killing the process .
  here is my code and I don't know what went wrong :</p>
  
  <pre><code> #include &lt;fcntl.h&gt;
   #include &lt;stdio.h&gt;
   #include  &lt;stdlib.h&gt;
   #include &lt;sys/stat.h&gt;
   #include &lt;unistd.h&gt;
   #include &lt;signal.h&gt;
   #define MAX_BUF 512
  
   void sigintHandler(int sig_num,char * myfifo)
  {
  puts("hello you there .please don't leave ");
  unlink(myfifo);
  exit(0);
  }
  
  int main()
  {
  
  printf("Access-Control-Allow-Origin: *\n");
  printf("Content-Type: text/event-stream\n\n");
  int fd;
  char buf[MAX_BUF];
  
  char * myfifo = "/tmp/omcipipe";
  struct stat st;
  </code></pre>
  
  <p>//catch ctrl c </p>
  
  <pre><code> sigaction(SIGINT, sigintHandler);
  
  
  
    //Create FIFO file 
       if (stat(myfifo, &amp;st) != 0)
       mkfifo(myfifo, 0666);
  
   fd = open(myfifo, O_RDONLY);
  while (read(fd, buf, MAX_BUF)&gt;0)
  {
      printf("data: %s", buf);
      printf("\n");
      fflush(stdout);
  } 
  
  puts( "----closing----"); 
  close(fd);
  unlink(myfifo);
  return 0;
  </code></pre>
  
  <p>}</p>