title: Handling CTRL-C in dummy shell
body: <p>I'm writing a dummy shell that should not terminate when the user types ctrl-C but should just generate a new prompt line.  Currently, my shell does not terminate when I type ctrl-C but it still does not print the new prompt line.  Do you know why this is the case and how I can fix this?</p>
  
  <p>My code is below:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;signal.h&gt;
  #define BUFFER_SIZE 1&lt;&lt;16
  #define ARRAY_SIZE 1&lt;&lt;16
  
  void INThandler(int);
  static void parseCmdArgs(char *buffer, char** cmdArgs, 
                  size_t cmdArgsSize, size_t *nargs)
  {
      char *bufCmdArgs[cmdArgsSize]; 
      char **temp;
      char *buf;
      size_t n, p;
  
      cmdArgs[0] = buf = bufCmdArgs[0] = buffer;  
  
      for(temp=bufCmdArgs; (*temp=strsep(&amp;buf, " \n\t")) != NULL ;){
          if ((*temp != '\0') &amp;&amp; (++temp &gt;= &amp;bufCmdArgs[cmdArgsSize]))
              break;
      }
  
      for (p=n=0; bufCmdArgs[n]!=NULL; n++){
          if(strlen(bufCmdArgs[n])&gt;0)
              cmdArgs[p++]=bufCmdArgs[n];
      }
  
      *nargs=p;
      cmdArgs[p]=NULL;
  }
  
  void INThandler(int sig)
  {
    printf("\n&gt; ");
    signal(sig, SIG_IGN);
    }
  int main(void)
  {
      char buffer[BUFFER_SIZE];
      char *args[ARRAY_SIZE];
      int retStatus;
      size_t nargs;
      pid_t pid;
  
  
      printf("$dummyshell\n");
      signal(SIGINT, INThandler);
      while(1){
  
          printf("&gt; ");
          fgets(buffer, BUFFER_SIZE, stdin);
          parseCmdArgs(buffer, args, ARRAY_SIZE, &amp;nargs); 
  
  
          if (nargs==0)
              continue;
  
          if (!strcmp(args[0], "help"))
          {
              printf("cat                    cd (absolute path references only\n");
              printf("exit\n");
              printf("help                   history\n");
              printf("jobs                   kill\n");
              printf("ls                     more\n");
              printf("ps                     pwd\n");
              continue;
          }
  
          if (!strcmp(args[0], "exit" ))
              exit(0);
  
      pid = fork();
  
          if (pid){      
              wait(&amp;retStatus);
          }
  
          else {
              if( execvp(args[0], args)) {
            fprintf(stderr, "%s\n", strerror(errno));
                  exit(127);
              }
          }
      /*  pid = fork();
      if (pid == 0)
        setpgrp();
      else if (pid)
        pid = wait(&amp;retStatus);
      else {
        if (execvp(args[0], args)){
          fprintf(stderr, "%s\n", strerror(errno));
          exit(127);
        }
        }*/
  
  
      }    
      return 0;
  }
  </code></pre>