ast_comparator/test/student_data/handout/shlab-handout/cases/reference_32_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) {
char* id = argv[1];
struct job_t *job;
int jobid;
if (id[0] == '%') {
jobid = atoi(id += sizeof(char));
}
if ((job = getjobjid(jobs, jobid)) == NULL) {
printf("job is not exist");
return;
}
if (!strcmp(argv[0], "bg")) {
job->state = BG;
send_signal(-1 * job->pid, SIGCONT);
} else if (!strcmp(argv[0], "fg")) {
job->state = FG;
send_signal(-1 * job->pid, SIGCONT);
waitfg(job->pid);
}
return;
}
void do_bgfg ( char * * argv ) { char * id = argv [ 1 ] ; struct job_t * job ; int jobid ; if ( id [ 0 ] == ' ' ) { jobid = atoi ( id += sizeof ( char ) ) ; } if ( ( job = getjobjid ( jobs , jobid ) ) == NULL ) { printf ( " " ) ; return ; } if ( ! strcmp ( argv [ 0 ] , " " ) ) { job -> state = BG ; send_signal ( -1 * job -> pid , SIGCONT ) ; } else if ( ! strcmp ( argv [ 0 ] , " " ) ) { job -> state = FG ; send_signal ( -1 * job -> pid , SIGCONT ) ; waitfg ( job -> pid ) ; } return ; }
do_bgfg - Execute the builtin bg and fg commands
do_bgfg - Execute the builtin bg and fg commands
//获得jobid //bg task //唤醒job