ast_comparator/test/student_data/handout/shlab-handout/cases/reference_39_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 o 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 o 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 o 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 [MAXLINE]; 
 pid_t pid; 
 sigset_t mask; 
 int bg = parseline (cmdline, argv); 
 if (argv [0] == NULL) { 
 return; 
 } 
 if ((sigemptyset (& mask)) <0) { 
 unix_error ("sigemptyset error"); 
 } 
 if ((sigaddset(& mask, SIGCHLD)) <0) { 
 unix_error ("sigaddset error"); 
 } 
 if (! (builtin_cmd (argv))) {
 if ((sigprocmask (SIG_BLOCK, & mask, NULL)) <0) { 
 unix_error ("sigprocmask error"); 
 } 
 if ((pid = fork ()) <0) { 
 unix_error ("fork error"); 
 } 
 else if (PID == 0) { 
 if (setpgid (0, 0) <0) { 
 unix_error ("setpgid error"); 
 } 
 if (sigprocmask (SIG_UNBLOCK, & mask, NULL) <0) { 
 unix_error ("sigprogmask error"); 
 } 
 if (execve (argv [0], argv, environ) <0) { 
 printf ("% s: Command not found. / n", argv [0]); 
 exit (0); 
 } 
 } 
 if (bg) { 
 addjob (jobs, pid, FG, cmdline); 
 if (sigprocmask (SIG_UNBLOCK, & mask, NULL) <0) { 
 unix_error ("sigprocmask error"); 
 } 
 waitfg (pid); 
 } 
 else { 
 int jid; 
 addjob (jobs, pid, BG, cmdline); 
 if (sigprocmask (SIG_UNBLOCK, & mask, NULL) <0) { 
 unix_error ("sigprocmask error"); 
 } 
 jid = pid2jid (pid); 
 printf ("[% d] (% d)% s", jid, pid, cmdline); 
 } 
 } 
 return; 
 }
void eval ( char * cmdline ) { char * argv [ MAXLINE ] ; pid_t pid ; sigset_t mask ; int bg = parseline ( cmdline , argv ) ; if ( argv [ 0 ] == NULL ) { return ; } if ( ( sigemptyset ( & mask ) ) < 0 ) { unix_error ( " " ) ; } if ( ( sigaddset ( & mask , SIGCHLD ) ) < 0 ) { unix_error ( " " ) ; } if ( ! ( builtin_cmd ( argv ) ) ) { if ( ( sigprocmask ( SIG_BLOCK , & mask , NULL ) ) < 0 ) { unix_error ( " " ) ; } if ( ( pid = fork ( ) ) < 0 ) { unix_error ( " " ) ; } else if ( PID == 0 ) { if ( setpgid ( 0 , 0 ) < 0 ) { unix_error ( " " ) ; } if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) < 0 ) { unix_error ( " " ) ; } if ( execve ( argv [ 0 ] , argv , environ ) < 0 ) { printf ( " " , argv [ 0 ] ) ; exit ( 0 ) ; } } if ( bg ) { addjob ( jobs , pid , FG , cmdline ) ; if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) < 0 ) { unix_error ( " " ) ; } waitfg ( pid ) ; } else { int jid ; addjob ( jobs , pid , BG , cmdline ) ; if ( sigprocmask ( SIG_UNBLOCK , & mask , NULL ) < 0 ) { unix_error ( " " ) ; } jid = pid2jid ( pid ) ; printf ( " " , jid , pid , cmdline ) ; } } 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
//ignore blank lines  // first check if it is a builtin command  // Make a new process group, check for error  // Printf ("child process group is% d / n", getpgid (0));  // Error check execve  // Return;  // Printf ("parent process group is% d / n", getpgid (0));  // wait for the foreground child to terminate. 