title: Executing a program using fork and exec
body: <p>I am new to C programming. I am trying to run a program given by the path specified by the user using the <code>fork()</code>, <code>exec()</code>, and <code>waitpid()</code> commands. I have been trying to get this to run correctly for hours now and I keep getting errors I am not sure how to troubleshoot, as soon as I solve one error, new ones arise. I was wondering if someone can help me understand why my implementation does not work smoothly?</p>
  
  <p>Many thanks </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  int main(void)  {
      char command1[256], command2[256], path[556];
      printf("# ");
      scanf("%s", command1);
      scanf("%s", command2);
      scanf("%s", path);
      if(strcmp(command1,"quit")==0)
          exit(0);
      else if(strcmp(command1, "run")==0 &amp;&amp; strcmp(command2, "command")==0){
  
              printf("%s", path);
  
              pid_t process;
  
              process = fork();
  
              //fork error
              if (process &lt; 0){
                 perror("fork");
                 exit(0);
              }
              else if (process &gt; 0){  //this is the parent process
                 execl(path, "sh" , "-c", ":ls -l *.c", 0);
              }
              else {//this is the child process
                 waitpid(process); //waits until the program terminates 
              }
  
      }
  
  
  
  
  return 0;
  
  }
  </code></pre>