Lines Matching refs:job
52 #define JP_MEDIUM 2 /* print [job-num] -/+ command */
53 #define JP_LONG 3 /* print [job-num] -/+ pid command */
60 /* Job.flags values */
61 #define JF_STARTED 0x001 /* set when all processes in job are started */
62 #define JF_WAITING 0x002 /* set if j_waitj() is waiting on job */
74 typedef struct job Job;
75 struct job {
76 Job *next; /* next job in list */
79 struct timeval systime; /* system time used by job */
80 struct timeval usrtime; /* user time used by job */
81 pid_t pgrp; /* process group of job */
82 pid_t ppid; /* pid of process that forked job */
83 int job; /* job number: %n */
85 volatile int state; /* job state */
99 #define JW_STOPPEDWAIT 0x04 /* wait even if job stopped */
103 #define JL_NOSUCH 1 /* no such job */
105 #define JL_INVALID 3 /* non-pid, non-% job id */
109 "no such job",
111 "argument must be %job or process id",
115 static Job *job_list; /* job list */
116 static Job *last_job;
117 static Job *async_job;
127 /* held_sigchld is set if sigchld occurs before a job is completely started */
137 static void j_set_async(Job *);
138 static void j_startjob(Job *);
139 static int j_waitj(Job *, int, const char *);
141 static void j_print(Job *, int, struct shf *);
142 static Job *j_lookup(const char *, int *);
143 static Job *new_job(void);
145 static void check_job(Job *);
146 static void put_job(Job *, int);
147 static void remove_job(Job *, const char *);
148 static int kill_job(Job *, int);
150 /* initialise job control */
203 /* job cleanup before shell exit */
208 Job *j;
257 /* turn job control on or off according to Flag(FMONITOR) */
274 /* wait to be given tty (POSIX.1, B.2, job control) */
311 warningf(false, "warning: won't have full job control");
347 Job *j;
358 /* no SIGCHLDs while messing with job and process lists */
379 pi.j = new_job(); /* fills in pi.j->job */
424 /* job control set up */
506 if (!(flags & XPIPEO)) { /* last process in a job */
513 coproc.job = (void *)pi.j;
518 shf_fprintf(shl_out, "[%d]", pi.j->job);
535 /* start the last job: only used for $(command) jobs */
551 /* wait for last job: only used for $(command) jobs */
556 Job *j;
564 warningf(true, "waitlast: no last job");
583 Job *j;
594 * wait for an unspecified job - always returns 0, so
606 /* don't report normal job completion */
630 /* kill (built-in) a job */
634 Job *j;
673 Job *j;
690 bi_errorf("job not job-controlled");
695 shprintf("[%d] ", j->job);
717 /* attach tty to job */
757 bi_errorf("cannot continue job %s: %s",
776 Job *j;
802 Job *j;
820 Job *j, *tmp;
866 Job *j, *tmp;
875 /* Remove job after doing reports so there aren't
890 /* Return pid of last process in last asynchronous job */
912 j_set_async(Job *j)
914 Job *jl, *oldest;
919 internal_warningf("j_async: job not started");
944 * Start a job: set STARTED, check for held signals and set j->last_proc
949 j_startjob(Job *j)
960 /* Don't call j_sigchld() as it may remove job... */
966 * wait for job to complete or change state
971 j_waitj(Job *j,
978 * No auto-notify on the job we are waiting on.
1011 * when the job is foregrounded. This is to
1035 * Only restore tty settings if job was originally
1049 * Don't use tty mode if job is stopped and
1066 * If it looks like user hit ^C to kill a job, pretend we got
1106 * SIGCHLD handler to reap children and update job states
1116 Job *j;
1123 * Don't wait for any processes if a job is partially started.
1147 /* find job and process structures for this pid */
1178 check_job(j); /* check to see if entire job is done */
1184 * from j_sigchld()). If no processes are running, the job status
1185 * and state are updated, asynchronous job notification is done and,
1186 * if unneeded, the job is removed.
1191 check_job(Job *j)
1198 internal_warningf("check_job: job started (flags 0x%x)",
1234 if (coproc.job == j) {
1235 coproc.job = NULL;
1240 * do "if job == 0 && write >= 0, close write".
1272 * Can't call j_notify() as it removes jobs. The job
1273 * must stay in the job list as j_waitj() may be
1274 * running with this job.
1291 j->job = -1;
1299 * Print job status in either short, medium or long format.
1304 j_print(Job *j, int how, struct shf *shf)
1326 filler = j->job > 10 ? "\n " : "\n ";
1372 shf_fprintf(shf, "[%d] %c ", j->job, jobchar);
1412 * Convert % sequence to job
1416 static Job *
1419 Job *j, *last_match;
1421 int len, job = 0;
1424 getn(cp, &job);
1427 if (j->last_proc && j->last_proc->pid == job)
1434 if (j->pgrp && j->pgrp == job)
1460 getn(cp, &job);
1462 if (j->job == job)
1503 static Job *free_jobs;
1507 * allocate a new job and fill in the job number.
1511 static Job *
1515 Job *newj, *j;
1521 newj = alloc(sizeof(Job), APERM);
1525 for (j = job_list; j && j->job != i; j = j->next)
1530 newj->job = i;
1555 * Take job out of job_list and put old structures into free list.
1561 remove_job(Job *j, const char *where)
1564 Job **prev, *curr;
1571 internal_warningf("remove_job: job not found (%s)", where);
1602 put_job(Job *j, int where)
1604 Job **prev, *curr;
1606 /* Remove job from list (if there) */
1633 * nuke a job (called when unable to start full job).
1638 kill_job(Job *j, int sig)