Lines Matching refs:Job
4 * Process and job control
109 #define JP_MEDIUM 2 /* print [job-num] -/+ command */
110 #define JP_LONG 3 /* print [job-num] -/+ pid command */
117 /* Job.flags values */
118 #define JF_STARTED 0x001 /* set when all processes in job are started */
119 #define JF_WAITING 0x002 /* set if j_waitj() is waiting on job */
131 typedef struct job Job;
132 struct job {
133 Job *next; /* next job in list */
134 int job; /* job number: %n */
136 int state; /* job state */
138 pid_t pgrp; /* process group of job */
139 pid_t ppid; /* pid of process that forked job */
141 clock_t systime; /* system time used by job */
142 clock_t usrtime; /* user time used by job */
158 #define JW_STOPPEDWAIT 0x04 /* wait even if job stopped */
162 #define JL_NOSUCH 1 /* no such job */
164 #define JL_INVALID 3 /* non-pid, non-% job id */
168 "no such job",
170 "argument must be %job or process id",
173 clock_t j_systime, j_usrtime; /* user and system time of last j_waitjed job */
175 static Job *job_list; /* job list */
176 static Job *last_job;
177 static Job *async_job;
185 /* held_sigchld is set if sigchld occurs before a job is completely started */
212 static void j_set_async ARGS((Job *j));
213 static void j_startjob ARGS((Job *j));
214 static int j_waitj ARGS((Job *j, int flags, const char *where));
216 static void j_print ARGS((Job *j, int how, struct shf *shf));
217 static Job *j_lookup ARGS((const char *cp, int *ecodep));
218 static Job *new_job ARGS((void));
220 static void check_job ARGS((Job *j));
221 static void put_job ARGS((Job *j, int where));
222 static void remove_job ARGS((Job *j, const char *where));
223 static int kill_job ARGS((Job *j, int sig));
225 /* initialize job control */
275 /* job cleanup before shell exit */
280 Job *j;
283 for (j = job_list; j != (Job *) 0; j = j->next) {
332 /* turn job control on or off according to Flag(FMONITOR) */
354 /* wait to be given tty (POSIX.1, B.2, job control) */
401 warningf(false, "warning: won't have full job control");
439 Job *j;
450 /* no SIGCHLD's while messing with job and process lists */
478 j = new_job(); /* fills in j->job */
527 /* job control set up */
642 if (!(flags & XPIPEO)) { /* last process in a job */
654 coproc.job = (void *) j; /* j using co-process input */
660 shf_fprintf(shl_out, "[%d]", j->job);
675 /* start the last job: only used for `command` jobs */
691 /* wait for last job: only used for `command` jobs */
696 Job *j;
704 warningf(true, "waitlast: no last job");
725 Job *j;
735 /* wait for an unspecified job - always returns 0, so
747 /* don't report normal job completion */
771 /* kill (built-in) a job */
777 Job *j;
784 if ((j = j_lookup(cp, &ecode)) == (Job *) 0) {
818 Job *j;
827 if ((j = j_lookup(cp, &ecode)) == (Job *) 0) {
835 bi_errorf("job not job-controlled");
840 shprintf("[%d] ", j->job);
861 /* attach tty to job */
882 async_job = (Job *) 0;
903 bi_errorf("cannot continue job %s: %s",
924 Job *j;
927 for (j = job_list; j != (Job *) 0; j = j->next) {
954 Job *j, *tmp;
968 if ((j = j_lookup(cp, &ecode)) == (Job *) 0) {
1001 Job *j, *tmp;
1010 /* Remove job after doing reports so there aren't
1025 /* Return pid of last process in last asynchronous job */
1047 Job *j;
1049 Job *jl, *oldest;
1054 internal_errorf(0, "j_async: job not started");
1060 oldest = (Job *) 0;
1077 /* Start a job: set STARTED, check for held signals and set j->last_proc
1083 Job *j;
1100 /* Don't call j_sigchld() as it may remove job... */
1106 * wait for job to complete or change state
1112 Job *j;
1119 * No auto-notify on the job we are waiting on.
1154 * when the job is foregrounded. This is to
1179 /* Only restore tty settings if job was originally
1194 /* Don't use tty mode if job is stopped and
1210 /* If it looks like user hit ^C to kill a job, pretend we got
1240 /* SIGCHLD handler to reap children and update job states
1249 Job *j;
1255 /* Don't wait for any processes if a job is partially started.
1275 /* find job and process structures for this pid */
1276 for (j = job_list; j != (Job *) 0; j = j->next)
1281 if (j == (Job *) 0) {
1304 check_job(j); /* check to see if entire job is done */
1315 * from j_sigchld()). If no processes are running, the job status
1316 * and state are updated, asynchronous job notification is done and,
1317 * if unneeded, the job is removed.
1323 Job *j;
1330 internal_errorf(0, "check_job: job started (flags 0x%x)",
1365 if (coproc.job == j) {
1366 coproc.job = (void *) 0;
1370 * do "if job == 0 && write >= 0, close write".
1402 /* Can't call j_notify() as it removes jobs. The job
1403 * must stay in the job list as j_waitj() may be
1404 * running with this job.
1418 j->job = -1;
1426 * Print job status in either short, medium or long format.
1432 Job *j;
1455 filler = j->job > 10 ? "\n " : "\n ";
1498 shf_fprintf(shf, "[%d] %c ", j->job, jobchar);
1537 /* Convert % sequence to job
1541 static Job *
1546 Job *j, *last_match;
1548 int len, job = 0;
1551 job = atoi(cp);
1553 for (j = job_list; j != (Job *) 0; j = j->next)
1554 if (j->last_proc && j->last_proc->pid == job)
1559 for (j = job_list; j != (Job *) 0; j = j->next)
1560 if (j->pgrp && j->pgrp == job)
1564 return (Job *) 0;
1569 return (Job *) 0;
1575 if (job_list != (Job *) 0)
1580 if (job_list != (Job *) 0 && job_list->next)
1586 job = atoi(cp);
1587 for (j = job_list; j != (Job *) 0; j = j->next)
1588 if (j->job == job)
1593 last_match = (Job *) 0;
1594 for (j = job_list; j != (Job *) 0; j = j->next)
1600 return (Job *) 0;
1610 last_match = (Job *) 0;
1611 for (j = job_list; j != (Job *) 0; j = j->next)
1616 return (Job *) 0;
1626 return (Job *) 0;
1629 static Job *free_jobs;
1632 /* allocate a new job and fill in the job number.
1636 static Job *
1640 Job *newj, *j;
1642 if (free_jobs != (Job *) 0) {
1646 newj = (Job *) alloc(sizeof(Job), APERM);
1650 for (j = job_list; j && j->job != i; j = j->next)
1652 if (j == (Job *) 0)
1655 newj->job = i;
1678 /* Take job out of job_list and put old structures into free list.
1685 Job *j;
1689 Job **prev, *curr;
1693 for (; curr != (Job *) 0 && curr != j; prev = &curr->next, curr = *prev)
1696 internal_errorf(0, "remove_job: job not found (%s)", where);
1715 last_job = (Job *) 0;
1717 async_job = (Job *) 0;
1727 Job *j;
1730 Job **prev, *curr;
1732 /* Remove job from list (if there) */
1758 /* nuke a job (called when unable to start full job).
1764 Job *j;