ast_comparator/test/student_data/anonymized/reference_30_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 isBG;	  			
	pid_t pid;		  	
	isBG = parseline(cmdline, argv); 
	sigset_t signalSet;  
	sigemptyset(&signalSet);
	sigaddset(&signalSet, SIGCHLD);
	if(!builtin_cmd(argv)) { 
		sigprocmask(SIG_BLOCK, &signalSet, NULL);
		if ((pid = fork()) == 0) { 
			setpgid(0, 0);
			sigprocmask(SIG_UNBLOCK, &signalSet, NULL);
			if (execve(argv[0], argv, environ) < 0) {
				printf("%s: Command not found\n", argv[0]);
				fflush(stdout);
				exit(0);
			}
			exit(0);
		}
			if(!isBG)
			{
				addjob(jobs, pid, FG, cmdline); 
				sigprocmask(SIG_UNBLOCK, &signalSet, NULL);
				waitfg(pid);
			}
			else
			{
				addjob(jobs, pid, BG, cmdline); 
				printf("[%d] (%d) %s",getjobpid(jobs, pid)->jid,pid,cmdline); 
				sigprocmask(SIG_UNBLOCK, &signalSet, NULL);   
			}
	}
}
void eval ( char * cmdline ) { char * argv [ MAXARGS ] ; int isBG ; pid_t pid ; isBG = parseline ( cmdline , argv ) ; sigset_t signalSet ; sigemptyset ( & signalSet ) ; sigaddset ( & signalSet , SIGCHLD ) ; if ( ! builtin_cmd ( argv ) ) { sigprocmask ( SIG_BLOCK , & signalSet , NULL ) ; if ( ( pid = fork ( ) ) == 0 ) { setpgid ( 0 , 0 ) ; sigprocmask ( SIG_UNBLOCK , & signalSet , NULL ) ; if ( execve ( argv [ 0 ] , argv , environ ) < 0 ) { printf ( " \n " , argv [ 0 ] ) ; fflush ( stdout ) ; exit ( 0 ) ; } exit ( 0 ) ; } if ( ! isBG ) { addjob ( jobs , pid , FG , cmdline ) ; sigprocmask ( SIG_UNBLOCK , & signalSet , NULL ) ; waitfg ( pid ) ; } else { addjob ( jobs , pid , BG , cmdline ) ; printf ( " " , getjobpid ( jobs , pid ) -> jid , pid , cmdline ) ; sigprocmask ( SIG_UNBLOCK , & signalSet , NULL ) ; } } }
eval - Evaluate the command line that the user has just typed in
eval - Evaluate the command line that the user has just typed in
/* array of arguments from command line */ /* Should the job run in bg or fg? */ /* process ID */ /* bg is 1 if background job, 0 if job is fg */ // initialize a set of signals that only contains SIGCHLD /* this line executes built-in commands; 
							  statements within if-statement are executed if not a built-in command */ /* block SIGCHLD signal */ /* Child runs user job */ // create new process group with child //unblock SIGCHLD signal // execute path as command /* Parent */ //add fg job // unblock SIGCHLD signal /* Parent waits for fg job to terminate */ //add bg job //print bg job details	 //unblock signal