title: redirect a process started with execv to /dev/null
body: <p>I have a program that <code>forks()</code>, and the child process is replaced by another process, say A, that is ran through invoking <code>execv(A)</code>.</p>
  
  <p>How do I redirect process <code>A</code>'s output to <code>/dev/null</code>??</p>
  
  <p>I've so far tried :
  (The handle error parts are taken care of, and no error occurs)</p>
  
  <pre><code>    pid = fork();
      //check for errors
      if (pid&lt;0){
                    //handle error
      }
      //the child process runs here
      if (pid==0){
          fd = open("/dev/null", O_WRONLY);
          if(fd &lt; 0){
                          //hadnle error
          }
          if ( dup2( fd, 1 )  != 1 ) {
                           //handle error 
          }
          if (execv(lgulppath.c_str(),args)&lt;0){
              //handle error
          }
      } 
  </code></pre>
  
  <p>However, that, understandably doesn't work , since it redirects the child process's output to <code>/dev/null</code> and not process <code>A</code>'s, later to replace the child, output.</p>
  
  <p>Any ideas?
  (I don't have the code of <code>A</code>'s process)</p>
  
  <p>Thanks</p>