ast_comparator/test/student_data/anonymized/reference_37_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[80];
    int isBg = parseline(cmdline,argv);
    pid_t pid;
    sigset_t mask;  
    if( sigemptyset( &mask ) )          
        unix_error( "sigemptyset error" );
    if( sigaddset( &mask, SIGCHLD ) )   
        unix_error( "sigaddset error" );
    if(!builtin_cmd(argv)){
        if( sigprocmask( SIG_BLOCK, &mask, NULL ) )   
            unix_error( "sigprocmask block error" );
		if( (pid = fork() ) == 0 ){     
			if( sigprocmask( SIG_UNBLOCK, &mask, NULL ) )  
                unix_error( "sigprocmask unblock error" );
            if( setpgid( 0, 0 ) )
                unix_error( "setpgid error" );
			if( ( execve( argv[0], argv, environ ) ) < 0 ){
                printf( "%s : command not found\n", argv[0] );
                fflush( stdout );
                exit( 0 );
            }
        }
        addjob( jobs, pid, isBg + 1, cmdline );     
        if( sigprocmask( SIG_UNBLOCK, &mask, NULL ) )
            unix_error( "sigprocmask unblock error" );
        if(!isBg){
            waitfg(pid); 
        } else {
            printf("[%d] (%d) %s",pid2jid(pid),pid,cmdline); 
        }
    }
    return;
}
void eval ( char * cmdline ) { char * argv [ 80 ] ; int isBg = parseline ( cmdline , argv ) ; pid_t pid ; sigset_t mask ; if ( sigemptyset ( & mask ) ) unix_error ( " " ) ; if ( sigaddset ( & mask , SIGCHLD ) ) unix_error ( " " ) ; if ( ! builtin_cmd ( argv ) ) { if ( sigprocmask ( SIG_BLOCK , & mask , NULL ) ) unix_error ( " " ) ; if ( ( pid = fork ( ) ) == 0 ) { if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) ) unix_error ( " " ) ; if ( setpgid ( 0 , 0 ) ) unix_error ( " " ) ; if ( ( execve ( argv [ 0 ] , argv , environ ) ) < 0 ) { printf ( " \n " , argv [ 0 ] ) ; fflush ( stdout ) ; exit ( 0 ) ; } } addjob ( jobs , pid , isBg + 1 , cmdline ) ; if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) ) unix_error ( " " ) ; if ( ! isBg ) { waitfg ( pid ) ; } else { printf ( " " , pid2jid ( pid ) , 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 .
// signal set // empty signal set // add signal SIGCHLD to signal set //to avoid a race, block SIGCHLD signals // ie. child pro // unblock signal SIGCHLD // create new process group // add the job to jobs list // isBg = 1 for background  process while isBg = 0 for foreground  process. So, we have defined FG=1 and BG = 2 => isBg + 1 // wait if it's a foreground process // print [jid] , (pid) and return to prompt w/o waiting.