ast_comparator/test/student_data/handout/shlab-handout/cases/reference_2_tsh.c
/* 
 * do_bgfg - Execute the builtin bg and fg commands
 */
Execute the builtin bg and fg commands
Execute the builtin bg and fg commands
void do_bgfg(char **argv) 
{
    struct job_t *job;
    char *id = argv[1];
    int jid;    
    if(id == NULL) {
        printf("%s command requires PID or %%jobid argument\n", argv[0]);
        return;
    }
    if(id[0] == '%') {  
        jid= atoi(&id[1]);  
        if(!(job= getjobjid(jobs, jid))) {  
            printf("%s: No such job\n", id);  
            return;  
        }  
    } 
    else if(isdigit(id[0])) { 
        pid_t pid= atoi(id);  
        if(!(job= getjobpid(jobs, pid))) {  
            printf("(%d): No such process\n", pid);  
            return;  
        }  
    }  
    else {
        printf("%s: argument must be a PID or %%jobid\n", argv[0]);
        return;
    }
    if(kill(-(job->pid), SIGCONT) < 0) {
        if(errno != ESRCH){
            unix_error("kill error");
        }
    }
    if(!strcmp("fg", argv[0])) {
        job->state = FG;
        waitfg(job->pid);
    } 
    else if(!strcmp("bg", argv[0])) {
        printf("[%d] (%d) %s", job->jid, job->pid, job->cmdline);
        job->state = BG;
    } 
    else {
        printf("bg/fg error: %s\n", argv[0]);
    }
}
void do_bgfg ( char * * argv ) { struct job_t * job ; char * id = argv [ 1 ] ; int jid ; if ( id == NULL ) { printf ( " \n " , argv [ 0 ] ) ; return ; } if ( id [ 0 ] == ' ' ) { jid = atoi ( & id [ 1 ] ) ; if ( ! ( job = getjobjid ( jobs , jid ) ) ) { printf ( " \n " , id ) ; return ; } } else if ( isdigit ( id [ 0 ] ) ) { pid_t pid = atoi ( id ) ; if ( ! ( job = getjobpid ( jobs , pid ) ) ) { printf ( " \n " , pid ) ; return ; } } else { printf ( " \n " , argv [ 0 ] ) ; return ; } if ( kill ( - ( job -> pid ) , SIGCONT ) < 0 ) { if ( errno != ESRCH ) { unix_error ( " " ) ; } } if ( ! strcmp ( " " , argv [ 0 ] ) ) { job -> state = FG ; waitfg ( job -> pid ) ; } else if ( ! strcmp ( " " , argv [ 0 ] ) ) { printf ( " " , job -> jid , job -> pid , job -> cmdline ) ; job -> state = BG ; } else { printf ( " \n " , argv [ 0 ] ) ; } }
do_bgfg - Execute the builtin bg and fg commands
do_bgfg - Execute the builtin bg and fg commands
// The id may be a PID or a JID // If id does not exist // For a JID // For a PID // Continue // To determine the bg and fg