Lines Matching defs:job
95 static struct job *jobtab; /* array of jobs */
101 static int curjob = -1; /* current job */
105 STATIC void restartjob(struct job *);
106 STATIC void freejob(struct job *);
107 STATIC struct job *getjob(const char *, int);
108 STATIC int dowait(int, struct job *, struct job **);
112 STATIC int jobstatus(const struct job *, int);
113 STATIC int waitproc(int, struct job *, int *);
154 * Turn job control on and off.
158 * System V doesn't have job control yet, this isn't a problem now.
189 out2str("sh: Need FIOCLEX or FD_CLOEXEC to support job control");
194 out2str("sh: can't access tty; job control turned off\n");
206 out2str("sh: need new tty driver to run job control; job control turned off\n");
220 } else { /* turning job control off */
255 struct job *jp;
263 error("job not created under job control");
296 set_curjob(struct job *jp, int mode)
298 struct job *jp1, *jp2;
317 case 0: /* job being deleted */
320 case 1: /* newly created job or backgrounded job,
335 case 2: /* newly stopped job - becomes curjob */
345 struct job *jp;
354 error("job not created under job control");
368 restartjob(struct job *jp)
376 error("Job [%d] does not have a process group", JNUM(jp));
399 error("Cannot continue job (%s)", strerror(e));
401 error("Job [%d] has no stopped processes", JNUM(jp));
404 * Now change state of all stopped processes in the job to running
405 * If there were any, the job is now running as well.
431 showjob(struct output *out, struct job *jp, int mode)
477 VTRACE(DBG_JOBS, ("showjob: freeing job %d\n",
592 * If the shell is interrupted in the process of creating a job, the
593 * result may be a job structure containing zero processes. Such structures
601 struct job *jp;
643 * Mark a job structure as unused.
647 freejob(struct job *jp)
663 * Extract the status of a completed job (for $?)
666 jobstatus(const struct job *jp, int raw)
702 struct job *job, *last;
704 struct job *jp;
774 job = NULL;
797 * It is possible to list the same job several
799 * "wait %% %2 102" where job 2 is current and pid 102
806 job = jp;
813 job && job->used ? (job->ref ? job->ref : "<no-arg>") : "none"));
835 job = NULL;
839 job = jp;
843 job = jp;
845 if (i < 0 && job == NULL) {
852 jp = job;
857 * There is at least 1 job running, so we can
861 job = NULL;
862 if ((i = dowait(WBLOCK|WNOFREE, NULL, &job)) == -1)
871 if (job == NULL)
875 * one of the reported job's processes exited,
878 if (job->state == JOBRUNNING)
881 job = jp; /* we want this, and it is done */
883 if (job->flags & JOBWANTED) {
886 job->flags &= ~JOBWANTED; /* got it */
887 rv = jobstatus(job, 0);
890 job->ref ? job->ref : "", rv));
891 if (any || job == last) {
893 fpid = job->ref;
907 "%d", job->ps[ job->nprocs ?
908 job->nprocs-1 : 0 ].pid);
915 if (job->state == JOBDONE) {
917 freejob(job);
931 if (oldwait && job->state == JOBDONE) {
933 freejob(job);
942 struct job *jp;
944 int pg = 0, onep = 0, job = 0;
949 case 'j': job = 1; break;
954 onep ? " -p" : "", job ? " -j" : "", jobs_invalid ? " [inv]" : "",
956 if (pg + onep + job > 1)
963 if (job) {
1017 sh_warnx("job control disabled");
1069 sh_warnx("Unknown job: %s", target);
1102 struct job *jp;
1113 * Convert a job name to a job structure.
1116 STATIC struct job *
1120 struct job *jp;
1123 const char *err_msg = "No such job: %s";
1129 err_msg = "No current job";
1140 err_msg = "No current job";
1146 err_msg = "No previous job";
1153 struct job *found;
1202 * observe the already existing job.
1207 struct job *jp;
1223 * async (ie: background) job is started in an interactive shell.
1227 jobstarted(struct job *jp)
1237 * Return a new job structure,
1240 struct job *
1244 struct job *jp;
1305 * Fork off a subshell. If we are doing job control, give the subshell its
1306 * own process group. Jp is a job structure that the job is to be added to.
1312 * process group even if job control is on.
1314 * When job control is turned off, background processes have their standard
1320 forkshell(struct job *jp, union node *n, int mode)
1344 forkparent(struct job *jp, union node *n, int mode, pid_t pid)
1351 * first process created for the job. If this proc
1378 forkchild(struct job *jp, union node *n, int mode, int vforked)
1398 jobctl = 0; /* do job control only in root shell */
1446 * Wait for job to finish.
1448 * Under job control we have the problem that while a child process is
1451 * active user may be hard to kill. With job control turned off, an
1465 waitforjob(struct job *jp)
1499 VTRACE(DBG_JOBS, ("waitforjob: job %d, nproc %d, status %d, st %x\n",
1505 * If we're doing job control, then we did a TIOCSPGRP which
1526 * If "job" is given (not NULL), then its jobcontrol status (and mflag)
1529 * or not varies depending what happened, and whether the affected job
1532 * If "changed" is not NULL, then the job which changed because a
1534 * if there is any such job, otherwise we set *changed = NULL.
1538 dowait(int flags, struct job *job, struct job **changed)
1543 struct job *jp;
1544 struct job *thisjob;
1549 VTRACE(DBG_JOBS|DBG_PROCS, ("dowait(%x) called for job %d%s\n",
1550 flags, JNUM(job), changed ? " [report change]" : ""));
1562 pid = waitproc(flags & WBLOCK, job, &status);
1577 * Otherwise, try to find the process, somewhere in our job table
1584 * For each job that is in use (this is one)
1590 * Now scan all our child processes of the job
1606 ("Job %d: changing status of proc %d from %#x to ",
1612 * and mark the job running as well.
1633 * We now know the affected job
1642 * the job is not stopped, or if the process
1644 * job is certainly not completed (done).
1654 * job, if we still show it as stopped, then...
1665 * completed, make it be the current job (%%)
1669 ("Job %d: changing state from %d to %d\n",
1682 * Now we have scanned all jobs. If we found the job that
1684 * fork processes without associating them with a job, when one
1696 if ((job == thisjob && (flags & WNOFREE) == 0) ||
1697 job != thisjob)
1704 "mode=%#x rootshell=%d, job=%p [%d]\n",
1706 job, JNUM(job)));
1724 * Do a wait system call. If job control is compiled in, we accept
1762 waitproc(int block, struct job *jp, int *status)
1803 struct job *jp;