title: Forking a process for simple shell
body: <p>I am writing a simple shell that needs to execute certain commands for a school assignment.  I've been mainly running the commands through the use of the system command.  However the assignment has a requirement that I'm not sure how to write or test:</p>
  
  <p>Your shell should implement each command by forking a new process and overlaying the child process with the requested function. The parent process should wait for the command to finish before continuing unless the command is followed up with a “&amp;” character.</p>
  
  <p>Here is a snippet of my code for the "clear" command:</p>
  
  <pre><code>void processLine(  const char * const s ) {
  
     const char * const clrStr = "clr";
     const int cLen    = strlen(clrStr);
     const int cVal    = strncmp(s, clrStr, cLen);
  
     if (!cVal) {
          char * locator = strchr(s, '&amp;');
          if (locator != NULL) {
             fork();
          }
          system("clear");
     }
  }
  </code></pre>
  
  <p>Would this work?  I'm not sure how to make the parent process wait for the command to finish.</p>