ast_comparator/test/student_data/handout/shlab-handout/cases/63_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 = parseline(cmdline, argv);
  if(argv[0] == NULL) return;
   Check whether the command is an built-in function
   If it is then execute it and return
  if (builtin_cmd(argv)) return;
  pid_t pid;
  sigset_t x;
	sigemptyset (&x);
	sigaddset(&x, SIGCHLD);
  if(sigprocmask(SIG_BLOCK, &x, NULL)){
  	unix_error("sigprocmask error");
  	return;
  }
  if((pid = fork()) < 0){
  	unix_error("fork error");
  	return; 
  }
  addjob(jobs,pid,bg+1,cmdline);
  if(pid == 0){
  	setpgid(0,0);
  	if(sigprocmask(SIG_UNBLOCK, &x, NULL)){
  		unix_error("sigprocmask error");
  	}
  	if(execve(argv[0], argv, environ) < 0){
  		fprintf(stderr, "%s: Command not found\n", argv[0]);
  		exit(0);
  	}
  }
  if(sigprocmask(SIG_UNBLOCK, &x, NULL)){
  	unix_error("sigprocmask error");
  	return;
  }
  if(!bg) {
  	waitfg(pid);
  } else
  	printf("[%d] (%d) %s",pid2jid(pid), pid, cmdline);
  return;
}
void eval ( char * cmdline ) { char * argv [ MAXARGS ] ; int bg = parseline ( cmdline , argv ) ; if ( argv [ 0 ] == NULL ) return ; if ( builtin_cmd ( argv ) ) return ; pid_t pid ; sigset_t x ; sigemptyset ( & x ) ; sigaddset ( & x , SIGCHLD ) ; if ( sigprocmask ( SIG_BLOCK , & x , NULL ) ) { unix_error ( " " ) ; return ; } if ( ( pid = fork ( ) ) < 0 ) { unix_error ( " " ) ; return ; } addjob ( jobs , pid , bg + 1 , cmdline ) ; if ( pid == 0 ) { setpgid ( 0 , 0 ) ; if ( sigprocmask ( SIG_UNBLOCK , & x , NULL ) ) { unix_error ( " " ) ; } if ( execve ( argv [ 0 ] , argv , environ ) < 0 ) { fprintf ( stderr , " \n " , argv [ 0 ] ) ; exit ( 0 ) ; } } if ( sigprocmask ( SIG_UNBLOCK , & x , NULL ) ) { unix_error ( " " ) ; return ; } if ( ! bg ) { 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 .
// // Check whether the command is an built-in function // If it is then execute it and return