ast_comparator/test/student_data/handout/shlab-handout/cases/reference_21_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(!builtin_cmd(argv))
    {
        if((pid = fork()) == 0)
        {
            setpgid(0,0);
            if(execvp(argv[0], argv) < 0)
            {
                printf("%s: Command not found\n", argv[0]);
                exit(1);
            }
        }
        else
        {
            if(!bg)
            {
                addjob(jobs, pid, FG, cmdline);
            }
            else
            {
                addjob(jobs, pid, BG, cmdline);
                printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline);
            }
            if (!bg)
            {
                waitfg(pid);
            }
        }
    }
    return;
}
void eval ( char * cmdline ) { char * argv [ MAXARGS ] ; int bg ; pid_t pid ; bg = parseline ( cmdline , argv ) ; if ( ! builtin_cmd ( argv ) ) { if ( ( pid = fork ( ) ) == 0 ) { setpgid ( 0 , 0 ) ; if ( execvp ( argv [ 0 ] , argv ) < 0 ) { printf ( " \n " , argv [ 0 ] ) ; exit ( 1 ) ; } } else { if ( ! bg ) { addjob ( jobs , pid , FG , cmdline ) ; } else { addjob ( jobs , pid , BG , cmdline ) ; printf ( " " , pid2jid ( pid ) , pid , cmdline ) ; } if ( ! bg ) { waitfg ( pid ) ; } } } return ; }
eval - Evaluate the command line that the user has just typed in
eval - Evaluate the command line that the user has just typed in
//Argument list of argv //bg tells whether the process should be running in foreground/background //Process Id // If it is not a built in fuinction // Forking the process and child runs the user job //If User enters invalid command // Parent adds job to the joblist // Foreground process // Background job  // Parent waits for the fg job to terminate