ast_comparator/test/student_data/handout/shlab-handout/cases/reference_5_tsh.c
/*
 * foreground_job - Execute foreground builtin command
 *
 * Get the job based on the input argument(job ID or process ID) 
 * and evaluate whether it can be foreground or not;
 * Wait for current process;
 * Update job's state and send SIGCONT signal.
 */
Execute foreground builtin command
Get the job based on the input argument(job ID or process ID)
and evaluate whether it can be foreground or not;
Wait for current process;
Update job's state and send SIGCONT signal.
Execute foreground builtin command Get the job based on the input argument ( job ID or process ID ) and evaluate whether it can be foreground or not ; Wait for current process ; Update job ' s state and send SIGCONT signal .
void
foreground_job(struct cmdline_tokens* tok_ptr)
{
    struct job_t* job_ptr;
    if (tok_ptr->argv[tok_ptr->argc - 1][0] == '%') {
        int jid = atoi(tok_ptr->argv[tok_ptr->argc - 1] + 1);
        job_ptr = getjobjid(job_list, jid);
        if (job_ptr == NULL) {
            printf("%%%d: No such job\n", jid);
            return;
        }
    }
    else if (isdigit(tok_ptr->argv[tok_ptr->argc - 1][0])) {
        int pid = atoi(tok_ptr->argv[tok_ptr->argc - 1]);
        job_ptr = getjobpid(job_list, pid);
        if (job_ptr == NULL) {
            printf("(%d): No such process\n", pid);
            return;
        }
    }
    else {
        printf("fg: argument mast be a PID or %%jobid\n");
        return;
    }
    tcsetpgrp(STDIN_FILENO, job_ptr->pid);
    job_ptr->state = FG;
    kill(job_ptr->pid, SIGCONT); 
    wait_fgjob(job_ptr);
}
void foreground_job ( struct cmdline_tokens * tok_ptr ) { struct job_t * job_ptr ; if ( tok_ptr -> argv [ tok_ptr -> argc - 1 ] [ 0 ] == ' ' ) { int jid = atoi ( tok_ptr -> argv [ tok_ptr -> argc - 1 ] + 1 ) ; job_ptr = getjobjid ( job_list , jid ) ; if ( job_ptr == NULL ) { printf ( " \n " , jid ) ; return ; } } else if ( isdigit ( tok_ptr -> argv [ tok_ptr -> argc - 1 ] [ 0 ] ) ) { int pid = atoi ( tok_ptr -> argv [ tok_ptr -> argc - 1 ] ) ; job_ptr = getjobpid ( job_list , pid ) ; if ( job_ptr == NULL ) { printf ( " \n " , pid ) ; return ; } } else { printf ( " \n " ) ; return ; } tcsetpgrp ( STDIN_FILENO , job_ptr -> pid ) ; job_ptr -> state = FG ; kill ( job_ptr -> pid , SIGCONT ) ; wait_fgjob ( job_ptr ) ; }
foreground_job - Execute foreground builtin command
 Get the job based on the input argument(job ID or process ID)
 and evaluate whether it can be foreground or not;
 Wait for current process;
 Update job's state and send SIGCONT signal.
foreground_job - Execute foreground builtin command Get the job based on the input argument ( job ID or process ID ) and evaluate whether it can be foreground or not ; Wait for current process ; Update job ' s state and send SIGCONT signal .
/* There is the job ID */ /* There is the process ID */ /* Set foreground process group ID to current job's PID 
     * associated with STDIN_FILENO 
     */ /* Update current process's state and send SIGCONT signal */ /* Wait current foreground process */