title: linuux - execvp : On executing ls command - get error " ls: cannot access /etc : No such file or directory"
body: <p>The below function takes in a array of char pointers Eg : 
  arr[0]: ls
  arr[1]: -l
  arr[2]: -a
  arr[3]: /etc
  arr[4]:NULL /* Since execvp expects a NULL at the end */ </p>
  
  <p>// <code>function call is runCmd(arr);</code>
  the function definition is below :</p>
  
  <pre><code>void runCmd(char *arr[]){
  
          pid_t child_pid,tpid;
          int child_status;
  
          child_pid = fork();
  
          if(child_pid == 0){
  
                  /* The child process executes the exec*/
  
                  execvp(arr[0],arr);
  
                  /*if it returns it must have failed */
                  fflush(stdout);
                  printf("Unknown Command \n");
                  exit(0);
          }
                  else {
                  /*  let the parent wait for the child */
                  do{
                           tpid = wait(&amp;child_status);
                  }while(tpid != child_pid);
          }
  }
  </code></pre>
  
  <p>After executing I get the message - </p>
  
  <pre><code>ls: cannot access /etc
  : No such file or directory
  </code></pre>