title: redirecting output of execvp into a file in C
body: <p>I don't know what I am doing wrong... but here is the snippet of code that is being executed:</p>
  
  <pre><code>if (fork() == 0)
      {       
               // child
          int fd = open(fileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  
          dup2(fd, 1);   // make stdout go to file
  
          execvp("ls","ls");
          close(fd);
              exit(0);
      }
  if(wait(&amp;status) == -1)
      {
          printf("ERROR REDIRECT\n");
      }
  </code></pre>
  
  <p><code>fileName</code> gets created but there is nothing inside.What am I doing wrong?</p>