title: How to make a program to restart itself? (Linux process)
body: <p>I'm trying to get my program to restart itself, but nothing seems to work. I tried using <code>fork()</code>, but after killing <em>the</em> <code>parent</code> process <em>the</em> <code>child</code> gets killed too.</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>void sigup_handler(int signum) {
      int pid = fork();
      if (pid == 0) {
          execve("prog2", NULL); 
      }
      else
          kill(getpid(), SIGTERM);
  }
  
  int main() {
      puts("Program 2 started.");
      signal(SIGHUP, sigup_handler);
      sleep(50); 
      puts("Program 2 terminated.");
      return 0;
  }
  </code></pre>