title: executing a program in C linux using fork and exec
body: <p>I want to execute a C program in Linux using <code>fork</code> and <code>exec</code> system calls.
  I have written a program <em>msg.c</em> and it's working fine. Then I wrote a program <em>msg1.c</em>.</p>
  
  <p>When I do <code>./a.out msg.c</code>, it's just printing <code>msg.c</code> as output but not executing my program.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt; /* for fork */
  #include &lt;sys/types.h&gt; /* for pid_t */
  #include &lt;sys/wait.h&gt; /* for wait */
  
  int main(int argc,char** argv)
  {
  /*Spawn a child to run the program.*/
      pid_t pid=fork();
      if (pid==0)
      { /* child process */
      //      static char *argv[]={"echo","Foo is my name.",NULL};
              execv("/bin/echo",argv);
              exit(127); /* only if execv fails */
      }
      else
      { /* pid!=0; parent process */
             waitpid(pid,0,0); /* wait for child to exit */
      }
   return 0;
  }
  </code></pre>