title: How to pass signals to child process
body: <p>Title may be a little confusing, so let me explain. I am trying to write a simple shell to practice my programming. I have got the get a command, fork, exec loop working. However, when I press <code>CTRL-C</code> while child process is still executing, my shell terminates, instead of child process (but child process would keep running). Here is the main function:</p>
  
  <pre><code>int main()
  {
      dynarray *args; /* pointer to a dynamic array */
      int bytes_read;
      size_t nbytes = 0;
      char *command;
      pid_t pid;
      printf("Enter command: ");
      while ((bytes_read = getline(&amp;command, &amp;nbytes, stdin)) != -1) {
          if (bytes_read == -1) {
              perror("getline");
              exit(EXIT_FAILURE);
          }
          pid = fork();
          if (pid == -1) {
              perror("fork");
              exit(EXIT_FAILURE);
          }
          else if (pid == 0) { /* child process */
              args = newdynarray();
              char *arg = strtok(command, " \n");
              while (arg != NULL) {
                  addstring(args, arg);
                  arg = strtok(NULL, " \n");
              }
              if (args-&gt;nval == 0) {
                  freedynarray(args);
                  continue;
              }
  
              addstring(args, NULL);
              char *fullpath = find_executable(args-&gt;strings[0]);
              if (fullpath == NULL) {
                  fprintf(stderr, "Couldn't find executable: %s\n", command);
                  exit(EXIT_FAILURE);
              }
              if (execv(fullpath, args-&gt;strings) == -1) {
                  perror("execv");
                  exit(EXIT_FAILURE);
              }
          } else {
              int status;
              waitpid(pid, &amp;status, 0);
          }
          printf("Enter command: ");
      } 
      return 0;
  }
  </code></pre>
  
  <p>I didn't include other parts, because I don't think they are relevant. How can I make my child process catch all the input from stdin until it terminates?</p>