title: Sending signal in C from child to Parents. "User defined signal 1: 30"
body: <p>I'm beginner to signal and practicing by writing a  function kill_parent_process that will be used as a signal handler.</p>
  
  <p>This func will asks parents to exit() (either sending SIGKILL or other methods). The way I did is let child sending a signal to parents and the handler exit(). But I do feel this is where the problem because when I exit, I might just exit in child process. However, it looks like the handler never been called. Here is my code</p>
  
  <pre><code>void kill_parent_process(int code) {
      fprintf(stderr, "KIll the Parent\n");
      exit(1);
  }
  
  int main() {
      struct sigaction sa;
      sa.sa_handler = kill_parent_process;
      sa.sa_flags = 0;
      sigemptyset(&amp;sa.sa_mask);
  
      int r = fork();
  
      if (r == 0) {
  
  
          sigaction(SIGUSR1, &amp;sa, NULL);
  
          kill(getppid(), SIGUSR1);
          exit(1);
      } else if (r &gt; 0) {
  
          while (1) {
              sleep(1);
              printf("%d\n",getpid());
          }
          int status;
          wait(&amp;status);
          if (WIFEXITED(status)) {
              int result = WEXITSTATUS(status);
              fprintf(stderr, "%d\n", result);
          }
  
        } 
      }
  </code></pre>
  
  <p>I receive a message User defined signal 1: 30 when I ran the program and kill_parent_process never been called. What is the problem with this code?</p>