int jobscmd(int argc, char *argv[]) { char *id; int ch, sformat, lformat; optind = optreset = 1; opterr = 0; sformat = lformat = 0; while ((ch = getopt(argc, argv, "ls")) != -1) { switch (ch) { case 'l': lformat = 1; break; case 's': sformat = 1; break; case '?': default: error("unknown option: -%c", optopt); } } argc -= optind; argv += optind; if (argc == 0) showjobs(0, sformat, lformat); else while ((id = *argv++) != NULL) showjob(getjob(id), 0, sformat, lformat); return (0); }
void showjobs(int change, int mode) { int jobno; struct job *jp; TRACE(("showjobs(%d) called\n", change)); checkzombies(); for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { if (! jp->used) continue; if (jp->nprocs == 0) { freejob(jp); continue; } if (change && ! jp->changed) continue; showjob(jp, mode); jp->changed = 0; /* Hack: discard jobs for which $! has not been referenced * in interactive mode when they terminate. */ if (jp->state == JOBDONE && !jp->remembered && (iflag || jp != bgjob)) { freejob(jp); } } }
void showjobs(struct output *out, int mode) { int jobno; struct job *jp; int silent = 0, gotpid; TRACE(("showjobs(%x) called\n", mode)); /* If not even one one job changed, there is nothing to do */ gotpid = dowait(0, NULL); while (dowait(0, NULL) > 0) continue; #ifdef JOBS /* * Check if we are not in our foreground group, and if not * put us in it. */ if (mflag && gotpid != -1 && tcgetpgrp(ttyfd) != getpid()) { if (tcsetpgrp(ttyfd, getpid()) == -1) error("Cannot set tty process group (%s) at %d", strerror(errno), __LINE__); TRACE(("repaired tty process group\n")); silent = 1; } #endif if (jobs_invalid) return; for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { if (!jp->used) continue; if (jp->nprocs == 0) { freejob(jp); continue; } if ((mode & SHOW_CHANGED) && !jp->changed) continue; if (silent && jp->changed) { jp->changed = 0; continue; } showjob(out, jp, mode); } }
int jobscmd(int argc, char **argv) { int mode, m; int sv = jobs_invalid; jobs_invalid = 0; mode = 0; while ((m = nextopt("lp"))) if (m == 'l') mode = SHOW_PID; else mode = SHOW_PGID; if (*argptr) do showjob(out1, getjob(*argptr,0), mode); while (*++argptr); else showjobs(out1, mode); jobs_invalid = sv; return 0; }
void showjobs(int change, int sformat, int lformat) { int jobno; struct job *jp; TRACE(("showjobs(%d) called\n", change)); while (dowait(0, (struct job *)NULL) > 0); for (jobno = 1, jp = jobtab ; jobno <= njobs ; jobno++, jp++) { if (! jp->used) continue; if (jp->nprocs == 0) { freejob(jp); continue; } if (change && ! jp->changed) continue; showjob(jp, 0, sformat, lformat); jp->changed = 0; if (jp->state == JOBDONE) { freejob(jp); } } }
int jobscmd(int argc, char *argv[]) { char *id; int ch, mode; optind = optreset = 1; opterr = 0; mode = SHOWJOBS_DEFAULT; while ((ch = getopt(argc, argv, "lps")) != -1) { switch (ch) { case 'l': mode = SHOWJOBS_VERBOSE; break; case 'p': mode = SHOWJOBS_PGIDS; break; case 's': mode = SHOWJOBS_PIDS; break; case '?': default: error("unknown option: -%c", optopt); } } argc -= optind; argv += optind; if (argc == 0) showjobs(0, mode); else while ((id = *argv++) != NULL) showjob(getjob(id), 0, mode); return (0); }
STATIC int dowait(int flags, struct job *job) { int pid; int status; struct procstat *sp; struct job *jp; struct job *thisjob; int done; int stopped; extern volatile char gotsig[]; TRACE(("dowait(%x) called\n", flags)); do { pid = waitproc(flags & WBLOCK, job, &status); TRACE(("wait returns pid %d, status %d\n", pid, status)); } while (pid == -1 && errno == EINTR && gotsig[SIGINT - 1] == 0); if (pid <= 0) return pid; INTOFF; thisjob = NULL; for (jp = jobtab ; jp < jobtab + njobs ; jp++) { if (jp->used) { done = 1; stopped = 1; for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) { if (sp->pid == -1) continue; if (sp->pid == pid) { TRACE(("Job %d: changing status of proc %d from 0x%x to 0x%x\n", jp - jobtab + 1, pid, sp->status, status)); sp->status = status; thisjob = jp; } if (sp->status == -1) stopped = 0; else if (WIFSTOPPED(sp->status)) done = 0; } if (stopped) { /* stopped or done */ int state = done ? JOBDONE : JOBSTOPPED; if (jp->state != state) { TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state)); jp->state = state; #if JOBS if (done) set_curjob(jp, 0); #endif } } } } if (thisjob && thisjob->state != JOBRUNNING) { int mode = 0; if (!rootshell || !iflag) mode = SHOW_SIGNALLED; if ((job == thisjob && (flags & WNOFREE) == 0) || (job != thisjob && (flags & WNOFREE) != 0)) mode = SHOW_SIGNALLED | SHOW_NO_FREE; if (mode) showjob(out2, thisjob, mode); else { TRACE(("Not printing status, rootshell=%d, job=%p\n", rootshell, job)); thisjob->changed = 1; } } INTON; return pid; }