ast_comparator/test/student_data/handout/shlab-handout/cases/53_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(const char *cmdline)
{
	bool background;
	char *argv[MAXARGS];
	pid_t child_pid;
	parse_line(cmdline, argv, &background);
	if (!builtin_cmd(argv))
	{
		if (sigprocmask(SIG_BLOCK, &sigchild, NULL) == -1)
			unix_error("Blocking SIGCHLD failed");
		child_pid = fork();
		if (child_pid == -1)
			unix_error("fork failed");
		else if (child_pid == 0)
		{
			if (setpgid(0, 0) == -1)
				unix_error("setpgid failed");
			if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
				unix_error("Unblocking SIGCHLD failed");
			execvp(argv[0], argv);
			if (errno == ENOENT)
				fprintf(stderr, "%s: Command not found\n", argv[0]);
			else
				unix_error(argv[0]);
			exit(0);
		}
		else
		{
			if (background)
			{
				struct job_t *job = add_job(jobs, child_pid, STATE_BACKGROUND, cmdline);
				if (job != NULL)
					printf("[%d] (%d) %s", job->jid, job->pid, job->cmdline);
				if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
					unix_error("Unblocking SIGCHLD failed");
			}
			else
			{
				add_job(jobs, child_pid, STATE_FOREGROUND, cmdline);
				if (sigprocmask(SIG_UNBLOCK, &sigchild, NULL) == -1)
					unix_error("Unblocking SIGCHLD failed");
				wait_fg_process(child_pid);
			}
		}
	}
}
void eval ( const char * cmdline ) { bool background ; char * argv [ MAXARGS ] ; pid_t child_pid ; parse_line ( cmdline , argv , & background ) ; if ( ! builtin_cmd ( argv ) ) { if ( sigprocmask ( SIG_BLOCK , & sigchild , NULL ) == -1 ) unix_error ( " " ) ; child_pid = fork ( ) ; if ( child_pid == -1 ) unix_error ( " " ) ; else if ( child_pid == 0 ) { if ( setpgid ( 0 , 0 ) == -1 ) unix_error ( " " ) ; if ( sigprocmask ( SIG_UNBLOCK , & sigchild , NULL ) == -1 ) unix_error ( " " ) ; execvp ( argv [ 0 ] , argv ) ; if ( errno == ENOENT ) fprintf ( stderr , " \n " , argv [ 0 ] ) ; else unix_error ( argv [ 0 ] ) ; exit ( 0 ) ; } else { if ( background ) { struct job_t * job = add_job ( jobs , child_pid , STATE_BACKGROUND , cmdline ) ; if ( job != NULL ) printf ( " " , job -> jid , job -> pid , job -> cmdline ) ; if ( sigprocmask ( SIG_UNBLOCK , & sigchild , NULL ) == -1 ) unix_error ( " " ) ; } else { add_job ( jobs , child_pid , STATE_FOREGROUND , cmdline ) ; if ( sigprocmask ( SIG_UNBLOCK , & sigchild , NULL ) == -1 ) unix_error ( " " ) ; wait_fg_process ( child_pid ) ; } } } }
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 .
// If exec fails,