title: how to pass command line arguments to a child process after fork()
body: <p>I have the following code draft. </p>
  
  <pre><code>#include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdlib.h&gt;    
  
  int main(int argc, char *argv[])
  {
  
      printf( "usage: %i filename", argc );
  
      pid_t pID = fork();
      if (pID == 0)                // child
      {
          // Code only executed by child process
          printf("Child PID: %i", pID);
  
          int file = open("/tmp/rtail", O_CREAT | O_WRONLY);
  
          //Now we redirect standard output to the file using dup2
          dup2(file,1);
  
          char tmp[30];
          sprintf(tmp, "cat `tail -f %s`", argv[1]);
      }
      else if (pID &lt; 0)            // failed to fork
      {
          printf("Failed to fork");
          exit(1);
          // Throw exception
      }
      else                                   // parent
      {
  
      }
  
      // Code executed by both parent and child.  
  
      return 0;
  }
  </code></pre>
  
  <p>How do I pass command line arguments to a child process? For example, running <code>./app alch.txt</code> I want </p>
  
  <pre><code>sprintf(tmp, "cat `tail -f %s`", argv[1]);
  </code></pre>
  
  <p>to produce </p>
  
  <pre><code>cat `tail -f alch.txt`
  </code></pre>
  
  <p>in tmp.</p>