ast_comparator/test/student_data/handout/shlab-handout/cases/prev_2_tsh.c
/*
 * eval - Evaluate the command line that the user has just typed in
 *
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.
 */
Evaluate the command line that the user has just typed in
If the user has requested a built-in command (quit, jobs, bg or fg)
then execute it immediately. Otherwise, fork a child process and
run the job in the context of the child. If the job is running in
the foreground, wait for it to terminate and then return.  Note:
each child process must have a unique process group ID so that our
background children don't receive SIGINT (SIGTSTP) from the kernel
when we type ctrl-c (ctrl-z) at the keyboard.
Evaluate the command line that the user has just typed in If the user has requested a built - in command ( quit jobs bg or fg ) then execute it immediately . Otherwise fork a child process and run the job in the context of the child . If the job is running in the foreground wait for it to terminate and then return . Note : each child process must have a unique process group ID so that our background children don ' t receive SIGINT ( SIGTSTP ) from the kernel when we type ctrl - c ( ctrl - z ) at the keyboard .
void eval(char *cmdline)
{
   char *argv[MAXARGS]; 
   int bg;
   pid_t pid;
   bg = parseline(cmdline, argv);
   if (argv[0] == NULL)
      return;
   if (!builtin_cmd(argv))
   {
      if ((pid = fork()) == 0) { 
         setpgid(0,0); 
         if (execve(argv[0], argv, environ) < 0) {  
            printf("%s: Command not found\n", argv[0]);
            exit(0);
         }
      }
      int state = bg ? BG : FG;
      addjob(jobs,pid,state,cmdline);
      if (!bg) {
         waitfg(pid); 
      }
      else
      {  
         int jid = pid2jid(pid);
         printf("[%d] (%d) %s",jid,pid,cmdline);
      }
   }
   return;
}
void eval ( char * cmdline ) { char * argv [ MAXARGS ] ; int bg ; pid_t pid ; bg = parseline ( cmdline , argv ) ; if ( argv [ 0 ] == NULL ) return ; if ( ! builtin_cmd ( argv ) ) { if ( ( pid = fork ( ) ) == 0 ) { setpgid ( 0 , 0 ) ; if ( execve ( argv [ 0 ] , argv , environ ) < 0 ) { printf ( " \n " , argv [ 0 ] ) ; exit ( 0 ) ; } } int state = bg ? BG : FG ; addjob ( jobs , pid , state , cmdline ) ; if ( ! bg ) { waitfg ( pid ) ; } else { int jid = pid2jid ( pid ) ; printf ( " " , jid , pid , cmdline ) ; } } return ; }
eval - Evaluate the command line that the user has just typed in
 If the user has requested a built-in command (quit, jobs, bg or fg)
 then execute it immediately.
eval - Evaluate the command line that the user has just typed in If the user has requested a built - in command ( quit jobs bg or fg ) then execute it immediately .
//bg will be 1 if background job cmdline is background  //printf("this is argv[0] : %s\n",argv[0]); //printf("this is argv[1] : %s\n",argv[1]); //printf("this is argv[2] : %s\n",argv[2]); //printf("this is argv[2] : %s\n",argv[3]); //if command is not builtin command  /* Child */ //setting the process group id to 0 /* Parent : prompt have to wait for foreground job to terminate */ //adding jobs //if foreground job  //waiting for foregroung job to complete //if background job //ex) [1] (370) ./myspin 4 &