void wait_for_fg(job *jobs) { int status; pid_t pid; do { pid = waitpid(-1, &status, WUNTRACED|WNOHANG); if(pid>0) { int jid = pid_to_jid(jobs, pid); if(jid != -1) set_job_status(&jobs[jid], status); } } while (fg_job(jobs) >= 0); }
/* * builtin - When user typed a shell built in cmd, the cmd will be executed *immediately and return a true value. Otherwise, return a 0 indicating not a *built in cmd. */ int builtin(struct cmdline_tokens* tok) { switch(tok->builtins) { case BUILTIN_NONE: return 0; case BUILTIN_QUIT: exit(0); case BUILTIN_JOBS: mylistjob(tok); return 1; case BUILTIN_FG: fg_job(tok); return 1; case BUILTIN_BG: bg_job(tok); return 1; default: return 0; } }