ast_comparator/test/student_data/handout/shlab-handout/cases/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;
  int id;
  if (argv[1] == NULL) {
    printf("%s command requires PID or %%jobid argument\n", argv[0]);
    return;
  }
  if (argv[1][0] == '%') {
    if (!isdigit(argv[1][1])) {
      printf("%s: argument must be PID or %%jobid\n", argv[0]);
      return;
    }
    id = atoi(&argv[1][1]);
    pid_t jid = (pid_t)id;
    if (!(job = getjobjid(jobs, jid))) {
      printf("%d: No such job\n", jid);
      return;
    }
  }
  else {
    if (!isdigit(argv[1][0])) {
      printf("%s: argument must be PID or %%jobid\n", argv[0]);
      return;
    }
    id = atoi(argv[1]);
    pid_t pid = (pid_t)id;
    if (!(job = getjobjid(jobs, pid))) {
      printf("(%d): No such process\n", pid);
      return;
    }
  }
  kill((-1) * (job->pid), SIGCONT);
  if (!strcmp(argv[0], "bg"))
    job->state = BG;
  else {
    job->state = FG;
    waitfg(job->pid);
  }
}
void do_bgfg ( char * * argv ) { struct job_t * job ; int id ; if ( argv [ 1 ] == NULL ) { printf ( " \n " , argv [ 0 ] ) ; return ; } if ( argv [ 1 ] [ 0 ] == ' ' ) { if ( ! isdigit ( argv [ 1 ] [ 1 ] ) ) { printf ( " \n " , argv [ 0 ] ) ; return ; } id = atoi ( & argv [ 1 ] [ 1 ] ) ; pid_t jid = ( pid_t ) id ; if ( ! ( job = getjobjid ( jobs , jid ) ) ) { printf ( " \n " , jid ) ; return ; } } else { if ( ! isdigit ( argv [ 1 ] [ 0 ] ) ) { printf ( " \n " , argv [ 0 ] ) ; return ; } id = atoi ( argv [ 1 ] ) ; pid_t pid = ( pid_t ) id ; if ( ! ( job = getjobjid ( jobs , pid ) ) ) { printf ( " \n " , pid ) ; return ; } } kill ( ( -1 ) * ( job -> pid ) , SIGCONT ) ; if ( ! strcmp ( argv [ 0 ] , " " ) ) job -> state = BG ; else { job -> state = FG ; waitfg ( job -> pid ) ; } }
do_bgfg - Execute the builtin bg and fg commands
do_bgfg - Execute the builtin bg and fg commands
/* no id */ /* jid case */ /* pid case */ /* continue signal */ /* set foreground or background state */