title: My children are missing Fork dup2 and execvp problems
body: <p>This code is supposed to read in </p>
  
  <pre><code>conc ls -l /bin &gt; Dout/concBin.txt , ls -l /usr/bin &gt; Dout/concUsrBin.txt , ls -l /etc &gt; Dout/concEtc.txt 
  </code></pre>
  
  <p>and then print out the ppid it is supposed to redirect after forking but before execing. currently it is reading in most of the files, but it prints out the bin (the example prints only the > , &lt; and file names and PPID) It only seems to generate concbin.txt to the Dout directory and then doesn't generate any other files. I think something is messed up with my for loop and my execvp.
  I apologize ahead of time for the mass of code. my professor provided a header file and a main file, those are working fine with my code. The stdin, stdout error checking printfs I put in are working so I am totally lost. I think I am not making enough children with my for loop in Argv</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/stat.h&gt;
  #include "cs3423p8.h"
  int concCmd (Cmd cmdM[], int iCmdCnt, Token tokenM[], int iTokenCnt);
  //int pipeCmd (Cmd cmdM[], int iCmdCnt, Token tokenM[], int iTokenCnt);
  
  //prints parents processID Child's ProcessID, the Command and Command arguments
  //fork each of the children, Max commands is 5. If any of the commands is redirect or output
  //do redirection after forking but before execing
   //redirect stdout for each child, and execvp to the particular command for child
  int concCmd (Cmd cmdM[], int iCmdCnt, Token tokenM[], int iTokenCnt)
  {
       int j;
       int i;
       int count = 0;
       long lForkPid;
       long lWaitPid;
       int iExitStatus = 0;
       char *execArgv[25];
       int fdin, fdout;
       //make children
       lForkPid = fork();
       //children made
       for(i = 0; i &lt; iCmdCnt; i++)
       {             
       //count =0;
           switch(lForkPid)
           {
               case -1:
               errExit("fork failed: %s", strerror(errno));
               break;
               case 0://child
  
               execArgv[0] = cmdM[i].szCmdNm;
               //count = 0;
               for(j = cmdM[i].iBeginIdx; j &lt;= cmdM[i].iEndIdx; j++)             
                   {
  
                       execArgv[count + 1] = tokenM[j];
                       count++;
                   }
                       execArgv[count] = NULL;
  
                       if (cmdM[i].iStdinRedirectIdx !=0)
                   {
                       printf("stdin redirect \n \n ");
  
                       fdin = open(tokenM[cmdM[i].iStdinRedirectIdx], O_RDONLY);
                       dup2(fdin, STDIN_FILENO);
                       close(fdin);
                       fprintf(stderr,"sTDIN REDIRECT Child Process: PID=%ld, PPID=%ld\n" , (long) getpid(), (long) getppid());
                       // execvp(cmdM[i].szCmdNm, execArgv);
                       //errExit("Child process failed to exec: %s", strerror(errno));
                    }
  
                    if (cmdM[i].iStdoutRedirectIdx !=0)
                    {
                        printf("stdout redirect \n\n");
  
                        fdout = open(tokenM[cmdM[i].iStdoutRedirectIdx], O_WRONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
                        dup2(fdout, STDOUT_FILENO);
                        close(fdout);
                        fprintf(stderr, "sTDOUT REDIRECT Child Process: PID=%ld, PPID=%ld\n", (long) getpid(), (long) getppid());
  
                    }
                    execvp(cmdM[i].szCmdNm, execArgv);
                    //errExit("Child process failed to exec: %s", strerror(errno));
  
  
                   // exit(0);
                default://parent
                    lWaitPid = wait(&amp;iExitStatus);
                       // if(lWaitPid == -1)
                       // errExit("wait error: %s", strerror(errno));
               }
          }
           return 0;
       }
  </code></pre>