1 /* $NetBSD: jobs.c,v 1.10 2011/10/16 17:12:11 joerg Exp $ */
4 * Process and job control
8 * Reworked/Rewritten version of Eric Gisin's/Ron Natalie's code by
9 * Larry Bouzane (larry@cs.mun.ca) and hacked again by
10 * Michael Rendell (michael@cs.mun.ca)
12 * The interface to the rest of the shell should probably be changed
13 * to allow use of vfork() when available but that would be way too much
16 * Notes regarding the copious ifdefs:
17 * - JOB_SIGS is independent of JOBS - it is defined if there are modern
18 * signal and wait routines available. This is preferred, even when
19 * JOBS is not defined, since the shell will not otherwise notice when
20 * background jobs die until the shell waits for a foreground process
22 * - TTY_PGRP defined iff JOBS is defined - defined if there are tty
24 * - NEED_PGRP_SYNC defined iff JOBS is defined - see comment below
26 #include <sys/cdefs.h>
29 __RCSID("$NetBSD: jobs.c,v 1.10 2011/10/16 17:12:11 joerg Exp $");
36 #include "ksh_times.h"
39 /* Start of system configuration stuff */
41 /* We keep CHILD_MAX zombie processes around (exact value isn't critical) */
43 # if defined(HAVE_SYSCONF) && defined(_SC_CHILD_MAX)
44 # define CHILD_MAX sysconf(_SC_CHILD_MAX)
45 # else /* _SC_CHILD_MAX */
46 # ifdef _POSIX_CHILD_MAX
47 # define CHILD_MAX ((_POSIX_CHILD_MAX) * 2)
48 # else /* _POSIX_CHILD_MAX */
50 # endif /* _POSIX_CHILD_MAX */
51 # endif /* _SC_CHILD_MAX */
52 #endif /* !CHILD_MAX */
55 # if defined(HAVE_TCSETPGRP) || defined(TIOCSPGRP)
59 # define setpgid setpgrp
60 # define getpgID() getpgrp(0)
62 # define getpgID() getpgrp()
64 # if defined(TTY_PGRP) && !defined(HAVE_TCSETPGRP)
65 int tcsetpgrp
ARGS((int fd
, pid_t grp
));
66 int tcgetpgrp
ARGS((int fd
));
73 return ioctl(fd
, TIOCSPGRP
, &grp
);
82 if ((r
= ioctl(fd
, TIOCGPGRP
, &grp
)) < 0)
86 # endif /* !HAVE_TCSETPGRP && TIOCSPGRP */
88 /* These so we can use ifdef xxx instead of if defined(JOBS) && defined(xxx) */
90 # undef NEED_PGRP_SYNC
93 /* End of system configuration stuff */
96 /* Order important! */
102 typedef struct proc Proc
;
104 Proc
*next
; /* next process in pipeline (if any) */
106 WAIT_T status
; /* wait status */
107 pid_t pid
; /* process id */
108 char command
[48]; /* process command string */
111 /* Notify/print flag - j_print() argument */
112 #define JP_NONE 0 /* don't print anything */
113 #define JP_SHORT 1 /* print signals processes were killed by */
114 #define JP_MEDIUM 2 /* print [job-num] -/+ command */
115 #define JP_LONG 3 /* print [job-num] -/+ pid command */
116 #define JP_PGRP 4 /* print pgrp */
118 /* put_job() flags */
119 #define PJ_ON_FRONT 0 /* at very front */
120 #define PJ_PAST_STOPPED 1 /* just past any stopped jobs */
122 /* Job.flags values */
123 #define JF_STARTED 0x001 /* set when all processes in job are started */
124 #define JF_WAITING 0x002 /* set if j_waitj() is waiting on job */
125 #define JF_W_ASYNCNOTIFY 0x004 /* set if waiting and async notification ok */
126 #define JF_XXCOM 0x008 /* set for `command` jobs */
127 #define JF_FG 0x010 /* running in foreground (also has tty pgrp) */
128 #define JF_SAVEDTTY 0x020 /* j->ttystate is valid */
129 #define JF_CHANGED 0x040 /* process has changed state */
130 #define JF_KNOWN 0x080 /* $! referenced */
131 #define JF_ZOMBIE 0x100 /* known, unwaited process */
132 #define JF_REMOVE 0x200 /* flagged for removal (j_jobs()/j_noityf()) */
133 #define JF_USETTYMODE 0x400 /* tty mode saved if process exits normally */
134 #define JF_SAVEDTTYPGRP 0x800 /* j->saved_ttypgrp is valid */
136 typedef struct job Job
;
138 Job
*next
; /* next job in list */
139 int job
; /* job number: %n */
140 int flags
; /* see JF_* */
141 int state
; /* job state */
142 int status
; /* exit status of last process */
143 pid_t pgrp
; /* process group of job */
144 pid_t ppid
; /* pid of process that forked job */
145 INT32 age
; /* number of jobs started */
146 clock_t systime
; /* system time used by job */
147 clock_t usrtime
; /* user time used by job */
148 Proc
*proc_list
; /* process list */
149 Proc
*last_proc
; /* last process in list */
151 Coproc_id coproc_id
; /* 0 or id of coprocess output pipe */
154 TTY_state ttystate
; /* saved tty state for stopped jobs */
155 pid_t saved_ttypgrp
; /* saved tty process group for stopped jobs */
156 #endif /* TTY_PGRP */
159 /* Flags for j_waitj() */
161 #define JW_INTERRUPT 0x01 /* ^C will stop the wait */
162 #define JW_ASYNCNOTIFY 0x02 /* asynchronous notification during wait ok */
163 #define JW_STOPPEDWAIT 0x04 /* wait even if job stopped */
165 /* Error codes for j_lookup() */
167 #define JL_NOSUCH 1 /* no such job */
168 #define JL_AMBIG 2 /* %foo or %?foo is ambiguous */
169 #define JL_INVALID 3 /* non-pid, non-% job id */
171 static const char *const lookup_msgs
[] = {
175 "argument must be %job or process id",
178 clock_t j_systime
, j_usrtime
; /* user and system time of last j_waitjed job */
180 static Job
*job_list
; /* job list */
181 static Job
*last_job
;
182 static Job
*async_job
;
183 static pid_t async_pid
;
185 static int nzombie
; /* # of zombies owned by this process */
186 static INT32 njobs
; /* # of jobs started */
187 static int child_max
; /* CHILD_MAX */
191 /* held_sigchld is set if sigchld occurs before a job is completely started */
192 static int held_sigchld
;
193 #endif /* JOB_SIGS */
196 static struct shf
*shl_j
;
199 #ifdef NEED_PGRP_SYNC
200 /* On some systems, the kernel doesn't count zombie processes when checking
201 * if a process group is valid, which can cause problems in creating the
202 * pipeline "cmd1 | cmd2": if cmd1 can die (and go into the zombie state)
203 * before cmd2 is started, the kernel doesn't allow the setpgid() for cmd2
204 * to succeed. Solution is to create a pipe between the parent and the first
205 * process; the first process doesn't do anything until the pipe is closed
206 * and the parent doesn't close the pipe until all the processes are started.
208 static int j_sync_pipe
[2];
209 static int j_sync_open
;
210 #endif /* NEED_PGRP_SYNC */
213 static int ttypgrp_ok
; /* set if can use tty pgrps */
214 static pid_t restore_ttypgrp
= -1;
215 static pid_t our_pgrp
;
216 static int const tt_sigs
[] = { SIGTSTP
, SIGTTIN
, SIGTTOU
};
217 #endif /* TTY_PGRP */
219 static void j_set_async
ARGS((Job
*j
));
220 static void j_startjob
ARGS((Job
*j
));
221 static int j_waitj
ARGS((Job
*j
, int flags
, const char *where
));
222 static RETSIGTYPE j_sigchld
ARGS((int sig
));
223 static void j_print
ARGS((Job
*j
, int how
, struct shf
*shf
));
224 static Job
*j_lookup
ARGS((const char *cp
, int *ecodep
));
225 static Job
*new_job
ARGS((void));
226 static Proc
*new_proc
ARGS((void));
227 static void check_job
ARGS((Job
*j
));
228 static void put_job
ARGS((Job
*j
, int where
));
229 static void remove_job
ARGS((Job
*j
, const char *where
));
230 static int kill_job
ARGS((Job
*j
, int sig
));
232 /* initialize job control */
237 child_max
= CHILD_MAX
; /* so syscon() isn't always being called */
240 sigemptyset(&sm_default
);
241 sigprocmask(SIG_SETMASK
, &sm_default
, (sigset_t
*) 0);
243 sigemptyset(&sm_sigchld
);
244 sigaddset(&sm_sigchld
, SIGCHLD
);
246 setsig(&sigtraps
[SIGCHLD
], j_sigchld
,
247 SS_RESTORE_ORIG
|SS_FORCE
|SS_SHTRAP
);
249 /* Make sure SIGCHLD isn't ignored - can do odd things under SYSV */
250 setsig(&sigtraps
[SIGCHLD
], SIG_DFL
, SS_RESTORE_ORIG
|SS_FORCE
);
251 #endif /* JOB_SIGS */
254 if (!mflagset
&& Flag(FTALKING
))
257 /* shl_j is used to do asynchronous notification (used in
258 * an interrupt handler, so need a distinct shf)
260 shl_j
= shf_fdopen(2, SHF_WR
, (struct shf
*) 0);
263 if (Flag(FMONITOR
) || Flag(FTALKING
)) {
266 /* the TF_SHELL_USES test is a kludge that lets us know if
267 * if the signals have been changed by the shell.
269 for (i
= NELEM(tt_sigs
); --i
>= 0; ) {
270 sigtraps
[tt_sigs
[i
]].flags
|= TF_SHELL_USES
;
271 /* j_change() sets this to SS_RESTORE_DFL if FMONITOR */
272 setsig(&sigtraps
[tt_sigs
[i
]], SIG_IGN
,
273 SS_RESTORE_IGN
|SS_FORCE
);
276 # endif /* TTY_PGRP */
278 /* j_change() calls tty_init() */
287 /* job cleanup before shell exit */
291 /* kill stopped, and possibly running, jobs */
295 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
) {
296 if (j
->ppid
== procpid
297 && (j
->state
== PSTOPPED
298 || (j
->state
== PRUNNING
299 && ((j
->flags
& JF_FG
)
300 || (Flag(FLOGIN
) && !Flag(FNOHUP
)
301 && procpid
== kshpid
)))))
307 killpg(j
->pgrp
, SIGHUP
);
309 if (j
->state
== PSTOPPED
) {
311 kill_job(j
, SIGCONT
);
313 killpg(j
->pgrp
, SIGCONT
);
324 if (kshpid
== procpid
&& restore_ttypgrp
>= 0) {
325 /* Need to restore the tty pgrp to what it was when the
326 * shell started up, so that the process that started us
327 * will be able to access the tty when we are done.
328 * Also need to restore our process group in case we are
329 * about to do an exec so that both our parent and the
330 * process we are to become will be able to access the tty.
332 tcsetpgrp(tty_fd
, restore_ttypgrp
);
333 setpgid(0, restore_ttypgrp
);
335 # endif /* TTY_PGRP */
336 if (Flag(FMONITOR
)) {
344 /* turn job control on or off according to Flag(FMONITOR) */
350 if (Flag(FMONITOR
)) {
351 /* Don't call get_tty() 'til we own the tty process group */
355 /* no controlling tty, no SIGT* */
356 ttypgrp_ok
= tty_fd
>= 0 && tty_devtty
;
358 if (ttypgrp_ok
&& (our_pgrp
= getpgID()) < 0) {
359 warningf(FALSE
, "j_init: getpgrp() failed: %s",
364 setsig(&sigtraps
[SIGTTIN
], SIG_DFL
,
365 SS_RESTORE_ORIG
|SS_FORCE
);
366 /* wait to be given tty (POSIX.1, B.2, job control) */
370 if ((ttypgrp
= tcgetpgrp(tty_fd
)) < 0) {
372 "j_init: tcgetpgrp() failed: %s",
377 if (ttypgrp
== our_pgrp
)
382 for (i
= NELEM(tt_sigs
); --i
>= 0; )
383 setsig(&sigtraps
[tt_sigs
[i
]], SIG_IGN
,
384 SS_RESTORE_DFL
|SS_FORCE
);
385 if (ttypgrp_ok
&& our_pgrp
!= kshpid
) {
386 if (setpgid(0, kshpid
) < 0) {
388 "j_init: setpgid() failed: %s",
392 if (tcsetpgrp(tty_fd
, kshpid
) < 0) {
394 "j_init: tcsetpgrp() failed: %s",
398 restore_ttypgrp
= our_pgrp
;
402 # if defined(NTTYDISC) && defined(TIOCSETD) && !defined(HAVE_TERMIOS_H) && !defined(HAVE_TERMIO_H)
404 int ldisc
= NTTYDISC
;
406 if (ioctl(tty_fd
, TIOCSETD
, &ldisc
) < 0)
408 "j_init: can't set new line discipline: %s",
411 # endif /* NTTYDISC && TIOCSETD */
413 warningf(FALSE
, "warning: won't have full job control");
414 # endif /* TTY_PGRP */
416 get_tty(tty_fd
, &tty_state
);
421 for (i
= NELEM(tt_sigs
); --i
>= 0; )
422 setsig(&sigtraps
[tt_sigs
[i
]], SIG_IGN
,
423 SS_RESTORE_IGN
|SS_FORCE
);
425 for (i
= NELEM(tt_sigs
); --i
>= 0; ) {
426 if (sigtraps
[tt_sigs
[i
]].flags
& (TF_ORIG_IGN
428 setsig(&sigtraps
[tt_sigs
[i
]],
429 (sigtraps
[tt_sigs
[i
]].flags
& TF_ORIG_IGN
) ? SIG_IGN
: SIG_DFL
,
430 SS_RESTORE_ORIG
|SS_FORCE
);
432 # endif /* TTY_PGRP */
439 /* execute tree in child subprocess */
441 exchild(t
, flags
, close_fd
)
444 int close_fd
; /* used if XPCLOSE or XCCLOSE */
446 static Proc
*last_proc
; /* for pipelines */
451 #endif /* JOB_SIGS */
459 /* Clear XFORK|XPCLOSE|XCCLOSE|XCOPROC|XPIPEO|XPIPEI|XXCOM|XBGND
460 * (also done in another execute() below)
462 return execute(t
, flags
& (XEXEC
| XERROK
));
465 /* no SIGCHLD's while messing with job and process lists */
466 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
467 #endif /* JOB_SIGS */
470 p
->next
= (Proc
*) 0;
472 WSTATUS(p
->status
) = 0;
475 /* link process into jobs list */
476 if (flags
&XPIPEI
) { /* continuing with a pipe */
478 internal_errorf(1, "exchild: XPIPEI and no last_job - pid %d", (int) procpid
);
483 #ifdef NEED_PGRP_SYNC
484 if (j_sync_open
) { /* should never happen */
486 closepipe(j_sync_pipe
);
488 /* don't do the sync pipe business if there is no pipeline */
489 if (flags
& XPIPEO
) {
490 openpipe(j_sync_pipe
);
493 #endif /* NEED_PGRP_SYNC */
494 j
= new_job(); /* fills in j->job */
495 /* we don't consider XXCOM's foreground since they don't get
496 * tty process group and we don't save or restore tty modes.
498 j
->flags
= (flags
& XXCOM
) ? JF_XXCOM
499 : ((flags
& XBGND
) ? 0 : (JF_FG
|JF_USETTYMODE
));
500 j
->usrtime
= j
->systime
= 0;
511 put_job(j
, PJ_PAST_STOPPED
);
514 snptreef(p
->command
, sizeof(p
->command
), "%T", t
);
516 /* create child process */
518 while ((i
= fork()) < 0 && errno
== EAGAIN
&& forksleep
< 32) {
519 if (intrsig
) /* allow user to ^C out... */
525 kill_job(j
, SIGKILL
);
526 remove_job(j
, "fork failed");
527 #ifdef NEED_PGRP_SYNC
529 closepipe(j_sync_pipe
);
532 #endif /* NEED_PGRP_SYNC */
534 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
535 #endif /* JOB_SIGS */
536 errorf("cannot fork - try again");
540 p
->pid
= procpid
= getpid();
545 /* job control set up */
546 if (Flag(FMONITOR
) && !(flags
&XXCOM
)) {
548 # ifdef NEED_PGRP_SYNC
549 int first_child_sync
= 0;
550 # endif /* NEED_PGRP_SYNC */
552 # ifdef NEED_PGRP_SYNC
555 * The Parent closes 0, keeps 1 open 'til the whole
556 * pipeline is started. The First child closes 1,
557 * keeps 0 open (reads from it). The remaining
558 * children just have to close 1 (parent has already
561 if (j
->pgrp
== 0) { /* First process */
562 close(j_sync_pipe
[ischild
]);
563 j_sync_pipe
[ischild
] = -1;
564 first_child_sync
= ischild
;
565 } else if (ischild
) {
567 closepipe(j_sync_pipe
);
570 # endif /* NEED_PGRP_SYNC */
571 if (j
->pgrp
== 0) { /* First process */
576 /* set pgrp in both parent and child to deal with race
579 setpgid(p
->pid
, j
->pgrp
);
581 /* YYY: should this be
582 if (ttypgrp_ok && ischild && !(flags&XBGND))
583 tcsetpgrp(tty_fd, j->pgrp);
584 instead? (see also YYY below)
586 if (ttypgrp_ok
&& dotty
&& !(flags
& XBGND
))
587 tcsetpgrp(tty_fd
, j
->pgrp
);
588 # endif /* TTY_PGRP */
589 # ifdef NEED_PGRP_SYNC
590 if (first_child_sync
) {
592 while (read(j_sync_pipe
[0], &c
, 1) == -1
595 close(j_sync_pipe
[0]);
598 # endif /* NEED_PGRP_SYNC */
602 /* used to close pipe input fd */
603 if (close_fd
>= 0 && (((flags
& XPCLOSE
) && !ischild
)
604 || ((flags
& XCCLOSE
) && ischild
)))
606 if (ischild
) { /* child */
608 /* Do this before restoring signal */
610 coproc_cleanup(FALSE
);
613 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
614 #endif /* JOB_SIGS */
615 cleanup_parents_env();
617 /* If FMONITOR or FTALKING is set, these signals are ignored,
618 * if neither FMONITOR nor FTALKING are set, the signals have
619 * their inherited values.
621 if (Flag(FMONITOR
) && !(flags
& XXCOM
)) {
622 for (i
= NELEM(tt_sigs
); --i
>= 0; )
623 setsig(&sigtraps
[tt_sigs
[i
]], SIG_DFL
,
624 SS_RESTORE_DFL
|SS_FORCE
);
626 #endif /* TTY_PGRP */
628 if (Flag(FBGNICE
) && (flags
& XBGND
))
630 #endif /* HAVE_NICE */
631 if ((flags
& XBGND
) && !Flag(FMONITOR
)) {
632 setsig(&sigtraps
[SIGINT
], SIG_IGN
,
633 SS_RESTORE_IGN
|SS_FORCE
);
634 setsig(&sigtraps
[SIGQUIT
], SIG_IGN
,
635 SS_RESTORE_IGN
|SS_FORCE
);
636 if (!(flags
& (XPIPEI
| XCOPROC
))) {
637 int fd
= open("/dev/null", 0);
639 (void) ksh_dup2(fd
, 0, TRUE
);
644 remove_job(j
, "child"); /* in case of `jobs` command */
657 execute(t
, (flags
& XERROK
) | XEXEC
); /* no return */
658 internal_errorf(0, "exchild: execute() returned");
663 /* shell (parent) stuff */
664 /* Ensure next child gets a (slightly) different $RANDOM sequence */
666 if (!(flags
& XPIPEO
)) { /* last process in a job */
668 /* YYY: Is this needed? (see also YYY above)
669 if (Flag(FMONITOR) && !(flags&(XXCOM|XBGND)))
670 tcsetpgrp(tty_fd, j->pgrp);
672 #endif /* TTY_PGRP */
675 if (flags
& XCOPROC
) {
676 j
->coproc_id
= coproc
.id
;
677 coproc
.njobs
++; /* n jobs using co-process output */
678 coproc
.job
= (void *) j
; /* j using co-process input */
683 if (Flag(FTALKING
)) {
684 shf_fprintf(shl_out
, "[%d]", j
->job
);
685 for (p
= j
->proc_list
; p
; p
= p
->next
)
686 shf_fprintf(shl_out
, " %d", p
->pid
);
687 shf_putchar('\n', shl_out
);
691 rv
= j_waitj(j
, JW_NONE
, "jw:last proc");
695 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
696 #endif /* JOB_SIGS */
701 /* start the last job: only used for `command` jobs */
708 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
709 #endif /* JOB_SIGS */
711 if (last_job
) { /* no need to report error - waitlast() will do it */
712 /* ensure it isn't removed by check_job() */
713 last_job
->flags
|= JF_WAITING
;
714 j_startjob(last_job
);
717 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
718 #endif /* JOB_SIGS */
721 /* wait for last job: only used for `command` jobs */
730 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
731 #endif /* JOB_SIGS */
734 if (!j
|| !(j
->flags
& JF_STARTED
)) {
736 warningf(TRUE
, "waitlast: no last job");
738 internal_errorf(0, "waitlast: not started");
740 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
741 #endif /* JOB_SIGS */
742 return 125; /* not so arbitrary, non-zero value */
745 rv
= j_waitj(j
, JW_NONE
, "jw:waitlast");
748 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
749 #endif /* JOB_SIGS */
754 /* wait for child, interruptable. */
763 int flags
= JW_INTERRUPT
|JW_ASYNCNOTIFY
;
767 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
768 #endif /* JOB_SIGS */
772 if (cp
== (char *) 0) {
773 /* wait for an unspecified job - always returns 0, so
774 * don't have to worry about exited/signaled jobs
776 for (j
= job_list
; j
; j
= j
->next
)
777 /* at&t ksh will wait for stopped jobs - we don't */
778 if (j
->ppid
== procpid
&& j
->state
== PRUNNING
)
782 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
783 #endif /* JOB_SIGS */
786 } else if ((j
= j_lookup(cp
, &ecode
))) {
787 /* don't report normal job completion */
788 flags
&= ~JW_ASYNCNOTIFY
;
789 if (j
->ppid
!= procpid
) {
791 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
792 #endif /* JOB_SIGS */
797 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
798 #endif /* JOB_SIGS */
799 if (ecode
!= JL_NOSUCH
)
800 bi_errorf("%s: %s", cp
, lookup_msgs
[ecode
]);
804 /* at&t ksh will wait for stopped jobs - we don't */
805 rv
= j_waitj(j
, flags
, "jw:waitfor");
808 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
809 #endif /* JOB_SIGS */
811 if (rv
< 0) /* we were interrupted */
817 /* kill (built-in) a job */
829 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
830 #endif /* JOB_SIGS */
832 if ((j
= j_lookup(cp
, &ecode
)) == (Job
*) 0) {
834 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
835 #endif /* JOB_SIGS */
836 bi_errorf("%s: %s", cp
, lookup_msgs
[ecode
]);
840 if (j
->pgrp
== 0) { /* started when !Flag(FMONITOR) */
841 if (kill_job(j
, sig
) < 0) {
842 bi_errorf("%s: %s", cp
, strerror(errno
));
847 if (j
->state
== PSTOPPED
&& (sig
== SIGTERM
|| sig
== SIGHUP
))
848 (void) killpg(j
->pgrp
, SIGCONT
);
850 if (killpg(j
->pgrp
, sig
) < 0) {
851 bi_errorf("%s: %s", cp
, strerror(errno
));
857 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
858 #endif /* JOB_SIGS */
864 /* fg and bg built-ins: called only if Flag(FMONITOR) set */
877 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
879 if ((j
= j_lookup(cp
, &ecode
)) == (Job
*) 0) {
880 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
881 bi_errorf("%s: %s", cp
, lookup_msgs
[ecode
]);
886 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
887 bi_errorf("job not job-controlled");
892 shprintf("[%d] ", j
->job
);
895 for (p
= j
->proc_list
; p
!= (Proc
*) 0; p
= p
->next
) {
896 if (p
->state
== PSTOPPED
) {
898 WSTATUS(p
->status
) = 0;
901 shprintf("%s%s", p
->command
, p
->next
? "| " : null
);
903 shprintf("%s", newline
);
904 shf_flush(shl_stdout
);
908 put_job(j
, PJ_PAST_STOPPED
);
913 /* attach tty to job */
914 if (j
->state
== PRUNNING
) {
915 if (ttypgrp_ok
&& (j
->flags
& JF_SAVEDTTY
)) {
916 set_tty(tty_fd
, &j
->ttystate
, TF_NONE
);
918 /* See comment in j_waitj regarding saved_ttypgrp. */
919 if (ttypgrp_ok
&& tcsetpgrp(tty_fd
, (j
->flags
& JF_SAVEDTTYPGRP
) ? j
->saved_ttypgrp
: j
->pgrp
) < 0) {
920 if (j
->flags
& JF_SAVEDTTY
) {
921 set_tty(tty_fd
, &tty_state
, TF_NONE
);
923 sigprocmask(SIG_SETMASK
, &omask
,
925 bi_errorf("1st tcsetpgrp(%d, %d) failed: %s",
926 tty_fd
, (int) ((j
->flags
& JF_SAVEDTTYPGRP
) ? j
->saved_ttypgrp
: j
->pgrp
), strerror(errno
));
930 # endif /* TTY_PGRP */
932 j
->flags
&= ~JF_KNOWN
;
934 async_job
= (Job
*) 0;
937 if (j
->state
== PRUNNING
&& killpg(j
->pgrp
, SIGCONT
) < 0) {
943 if (ttypgrp_ok
&& (j
->flags
& JF_SAVEDTTY
)) {
944 set_tty(tty_fd
, &tty_state
, TF_NONE
);
946 if (ttypgrp_ok
&& tcsetpgrp(tty_fd
, our_pgrp
) < 0) {
948 "fg: 2nd tcsetpgrp(%d, %d) failed: %s",
949 tty_fd
, (int) our_pgrp
,
952 # endif /* TTY_PGRP */
954 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
955 bi_errorf("cannot continue job %s: %s",
962 j
->flags
&= ~(JF_SAVEDTTY
| JF_SAVEDTTYPGRP
);
964 # endif /* TTY_PGRP */
965 rv
= j_waitj(j
, JW_NONE
, "jw:resume");
967 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
972 /* are there any running or stopped jobs ? */
979 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
) {
981 if (j
->ppid
== procpid
&& j
->state
== PSTOPPED
)
984 if (Flag(FLOGIN
) && !Flag(FNOHUP
) && procpid
== kshpid
985 && j
->ppid
== procpid
&& j
->state
== PRUNNING
)
989 shellf("You have %s%s%s jobs\n",
990 which
& 1 ? "stopped" : "",
991 which
== 3 ? " and " : "",
992 which
& 2 ? "running" : "");
999 /* list jobs for jobs built-in */
1001 j_jobs(cp
, slp
, nflag
)
1003 int slp
; /* 0: short, 1: long, 2: pgrp */
1012 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
1013 #endif /* JOB_SIGS */
1015 if (nflag
< 0) { /* kludge: print zombies */
1022 if ((j
= j_lookup(cp
, &ecode
)) == (Job
*) 0) {
1024 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
1025 #endif /* JOB_SIGS */
1026 bi_errorf("%s: %s", cp
, lookup_msgs
[ecode
]);
1031 how
= slp
== 0 ? JP_MEDIUM
: (slp
== 1 ? JP_LONG
: JP_PGRP
);
1032 for (; j
; j
= j
->next
) {
1033 if ((!(j
->flags
& JF_ZOMBIE
) || zflag
)
1034 && (!nflag
|| (j
->flags
& JF_CHANGED
)))
1036 j_print(j
, how
, shl_stdout
);
1037 if (j
->state
== PEXITED
|| j
->state
== PSIGNALLED
)
1038 j
->flags
|= JF_REMOVE
;
1043 /* Remove jobs after printing so there won't be multiple + or - jobs */
1044 for (j
= job_list
; j
; j
= tmp
) {
1046 if (j
->flags
& JF_REMOVE
)
1047 remove_job(j
, "jobs");
1050 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
1051 #endif /* JOB_SIGS */
1055 /* list jobs for top-level notification */
1063 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
1064 #endif /* JOB_SIGS */
1065 for (j
= job_list
; j
; j
= j
->next
) {
1067 if (Flag(FMONITOR
) && (j
->flags
& JF_CHANGED
))
1068 j_print(j
, JP_MEDIUM
, shl_out
);
1070 /* Remove job after doing reports so there aren't
1071 * multiple +/- jobs.
1073 if (j
->state
== PEXITED
|| j
->state
== PSIGNALLED
)
1074 j
->flags
|= JF_REMOVE
;
1076 for (j
= job_list
; j
; j
= tmp
) {
1078 if (j
->flags
& JF_REMOVE
)
1079 remove_job(j
, "notify");
1083 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
1084 #endif /* JOB_SIGS */
1087 /* Return pid of last process in last asynchronous job */
1094 sigprocmask(SIG_BLOCK
, &sm_sigchld
, &omask
);
1095 #endif /* JOB_SIGS */
1098 async_job
->flags
|= JF_KNOWN
;
1101 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*) 0);
1102 #endif /* JOB_SIGS */
1107 /* Make j the last async process
1109 * If jobs are compiled in then this routine expects sigchld to be blocked.
1117 if (async_job
&& (async_job
->flags
& (JF_KNOWN
|JF_ZOMBIE
)) == JF_ZOMBIE
)
1118 remove_job(async_job
, "async");
1119 if (!(j
->flags
& JF_STARTED
)) {
1120 internal_errorf(0, "j_async: job not started");
1124 async_pid
= j
->last_proc
->pid
;
1125 while (nzombie
> child_max
) {
1127 for (jl
= job_list
; jl
; jl
= jl
->next
)
1128 if (jl
!= async_job
&& (jl
->flags
& JF_ZOMBIE
)
1129 && (!oldest
|| jl
->age
< oldest
->age
))
1133 if (!(async_job
->flags
& JF_ZOMBIE
) || nzombie
!= 1) {
1134 internal_errorf(0, "j_async: bad nzombie (%d)", nzombie
);
1139 remove_job(oldest
, "zombie");
1143 /* Start a job: set STARTED, check for held signals and set j->last_proc
1145 * If jobs are compiled in then this routine expects sigchld to be blocked.
1153 j
->flags
|= JF_STARTED
;
1154 for (p
= j
->proc_list
; p
->next
; p
= p
->next
)
1158 #ifdef NEED_PGRP_SYNC
1161 closepipe(j_sync_pipe
);
1163 #endif /* NEED_PGRP_SYNC */
1167 /* Don't call j_sigchld() as it may remove job... */
1168 kill(procpid
, SIGCHLD
);
1170 #endif /* JOB_SIGS */
1174 * wait for job to complete or change state
1176 * If jobs are compiled in then this routine expects sigchld to be blocked.
1179 j_waitj(j
, flags
, where
)
1181 int flags
; /* see JW_* */
1187 * No auto-notify on the job we are waiting on.
1189 j
->flags
|= JF_WAITING
;
1190 if (flags
& JW_ASYNCNOTIFY
)
1191 j
->flags
|= JF_W_ASYNCNOTIFY
;
1193 if (!Flag(FMONITOR
))
1194 flags
|= JW_STOPPEDWAIT
;
1196 while ((volatile int) j
->state
== PRUNNING
1197 || ((flags
& JW_STOPPEDWAIT
)
1198 && (volatile int) j
->state
== PSTOPPED
))
1201 sigsuspend(&sm_default
);
1202 #else /* JOB_SIGS */
1204 #endif /* JOB_SIGS */
1206 int oldf
= j
->flags
& (JF_WAITING
|JF_W_ASYNCNOTIFY
);
1207 j
->flags
&= ~(JF_WAITING
|JF_W_ASYNCNOTIFY
);
1209 j
->flags
|= oldf
; /* not reached... */
1211 if ((flags
& JW_INTERRUPT
) && (rv
= trap_pending())) {
1212 j
->flags
&= ~(JF_WAITING
|JF_W_ASYNCNOTIFY
);
1216 j
->flags
&= ~(JF_WAITING
|JF_W_ASYNCNOTIFY
);
1218 if (j
->flags
& JF_FG
) {
1223 if (Flag(FMONITOR
) && ttypgrp_ok
&& j
->pgrp
) {
1225 * Save the tty's current pgrp so it can be restored
1226 * when the job is foregrounded. This is to
1227 * deal with things like the GNU su which does
1228 * a fork/exec instead of an exec (the fork means
1229 * the execed shell gets a different pid from its
1230 * pgrp, so naturally it sets its pgrp and gets hosed
1231 * when it gets foregrounded by the parent shell, which
1232 * has restored the tty's pgrp to that of the su
1235 if (j
->state
== PSTOPPED
1236 && (j
->saved_ttypgrp
= tcgetpgrp(tty_fd
)) >= 0)
1237 j
->flags
|= JF_SAVEDTTYPGRP
;
1238 if (tcsetpgrp(tty_fd
, our_pgrp
) < 0) {
1240 "j_waitj: tcsetpgrp(%d, %d) failed: %s",
1241 tty_fd
, (int) our_pgrp
,
1244 if (j
->state
== PSTOPPED
) {
1245 j
->flags
|= JF_SAVEDTTY
;
1246 get_tty(tty_fd
, &j
->ttystate
);
1249 #endif /* TTY_PGRP */
1251 /* Only restore tty settings if job was originally
1252 * started in the foreground. Problems can be
1253 * caused by things like `more foobar &' which will
1254 * typically get and save the shell's vi/emacs tty
1255 * settings before setting up the tty for itself;
1256 * when more exits, it restores the `original'
1257 * settings, and things go down hill from there...
1259 if (j
->state
== PEXITED
&& j
->status
== 0
1260 && (j
->flags
& JF_USETTYMODE
))
1262 get_tty(tty_fd
, &tty_state
);
1264 set_tty(tty_fd
, &tty_state
,
1265 (j
->state
== PEXITED
) ? 0 : TF_MIPSKLUDGE
);
1266 /* Don't use tty mode if job is stopped and
1267 * later restarted and exits. Consider
1274 * mode should be that of the stty, not what
1275 * was before the vi started.
1277 if (j
->state
== PSTOPPED
)
1278 j
->flags
&= ~JF_USETTYMODE
;
1282 /* If it looks like user hit ^C to kill a job, pretend we got
1283 * one too to break out of for loops, etc. (at&t ksh does this
1284 * even when not monitoring, but this doesn't make sense since
1285 * a tty generated ^C goes to the whole process group)
1287 status
= j
->last_proc
->status
;
1288 if (Flag(FMONITOR
) && j
->state
== PSIGNALLED
1289 && WIFSIGNALED(status
)
1290 && (sigtraps
[WTERMSIG(status
)].flags
& TF_TTY_INTR
))
1291 trapsig(WTERMSIG(status
));
1295 j_usrtime
= j
->usrtime
;
1296 j_systime
= j
->systime
;
1299 if (!(flags
& JW_ASYNCNOTIFY
)
1300 && (!Flag(FMONITOR
) || j
->state
!= PSTOPPED
))
1302 j_print(j
, JP_SHORT
, shl_out
);
1305 if (j
->state
!= PSTOPPED
1306 && (!Flag(FMONITOR
) || !(flags
& JW_ASYNCNOTIFY
)))
1307 remove_job(j
, where
);
1312 /* SIGCHLD handler to reap children and update job states
1314 * If jobs are compiled in then this routine expects sigchld to be blocked.
1322 Proc
UNINITIALIZED(*p
);
1328 /* Don't wait for any processes if a job is partially started.
1329 * This is so we don't do away with the process group leader
1330 * before all the processes in a pipe line are started (so the
1331 * setpgid() won't fail)
1333 for (j
= job_list
; j
; j
= j
->next
)
1334 if (j
->ppid
== procpid
&& !(j
->flags
& JF_STARTED
)) {
1338 #endif /* JOB_SIGS */
1343 pid
= ksh_waitpid(-1, &status
, (WNOHANG
|WUNTRACED
));
1344 #else /* JOB_SIGS */
1345 pid
= wait(&status
);
1346 #endif /* JOB_SIGS */
1348 if (pid
<= 0) /* return if would block (0) ... */
1349 break; /* ... or no children or interrupted (-1) */
1353 /* find job and process structures for this pid */
1354 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1355 for (p
= j
->proc_list
; p
!= (Proc
*) 0; p
= p
->next
)
1359 if (j
== (Job
*) 0) {
1360 /* Can occur if process has kids, then execs shell
1361 warningf(TRUE, "bad process waited for (pid = %d)",
1368 j
->usrtime
+= t1
.tms_cutime
- t0
.tms_cutime
;
1369 j
->systime
+= t1
.tms_cstime
- t0
.tms_cstime
;
1373 if (WIFSTOPPED(status
))
1374 p
->state
= PSTOPPED
;
1377 if (WIFSIGNALED(status
))
1378 p
->state
= PSIGNALLED
;
1382 check_job(j
); /* check to see if entire job is done */
1386 #else /* JOB_SIGS */
1388 #endif /* JOB_SIGS */
1396 * Called only when a process in j has exited/stopped (ie, called only
1397 * from j_sigchld()). If no processes are running, the job status
1398 * and state are updated, asynchronous job notification is done and,
1399 * if unneeded, the job is removed.
1401 * If jobs are compiled in then this routine expects sigchld to be blocked.
1410 /* XXX debugging (nasty - interrupt routine using shl_out) */
1411 if (!(j
->flags
& JF_STARTED
)) {
1412 internal_errorf(0, "check_job: job started (flags 0x%x)",
1418 for (p
=j
->proc_list
; p
!= (Proc
*) 0; p
= p
->next
) {
1419 if (p
->state
== PRUNNING
)
1420 return; /* some processes still running */
1421 if (p
->state
> jstate
)
1426 switch (j
->last_proc
->state
) {
1428 j
->status
= WEXITSTATUS(j
->last_proc
->status
);
1431 j
->status
= 128 + WTERMSIG(j
->last_proc
->status
);
1439 /* Note when co-process dies: can't be done in j_wait() nor
1440 * remove_job() since neither may be called for non-interactive
1443 if (j
->state
== PEXITED
|| j
->state
== PSIGNALLED
) {
1444 /* No need to keep co-process input any more
1445 * (at least, this is what ksh93d thinks)
1447 if (coproc
.job
== j
) {
1448 coproc
.job
= (void *) 0;
1449 /* XXX would be nice to get the closes out of here
1450 * so they aren't done in the signal handler.
1451 * Would mean a check in coproc_getfd() to
1452 * do "if job == 0 && write >= 0, close write".
1454 coproc_write_close(coproc
.write
);
1456 /* Do we need to keep the output? */
1457 if (j
->coproc_id
&& j
->coproc_id
== coproc
.id
1458 && --coproc
.njobs
== 0)
1459 coproc_readw_close(coproc
.read
);
1463 j
->flags
|= JF_CHANGED
;
1465 if (Flag(FMONITOR
) && !(j
->flags
& JF_XXCOM
)) {
1466 /* Only put stopped jobs at the front to avoid confusing
1467 * the user (don't want finished jobs effecting %+ or %-)
1469 if (j
->state
== PSTOPPED
)
1470 put_job(j
, PJ_ON_FRONT
);
1472 && (j
->flags
& (JF_WAITING
|JF_W_ASYNCNOTIFY
)) != JF_WAITING
)
1474 /* Look for the real file descriptor 2 */
1479 for (ep
= e
; ep
; ep
= ep
->oenv
)
1480 if (ep
->savefd
&& ep
->savefd
[2])
1482 shf_reopen(fd
, SHF_WR
, shl_j
);
1484 /* Can't call j_notify() as it removes jobs. The job
1485 * must stay in the job list as j_waitj() may be
1486 * running with this job.
1488 j_print(j
, JP_MEDIUM
, shl_j
);
1490 if (!(j
->flags
& JF_WAITING
) && j
->state
!= PSTOPPED
)
1491 remove_job(j
, "notify");
1495 if (!Flag(FMONITOR
) && !(j
->flags
& (JF_WAITING
|JF_FG
))
1496 && j
->state
!= PSTOPPED
)
1498 if (j
== async_job
|| (j
->flags
& JF_KNOWN
)) {
1499 j
->flags
|= JF_ZOMBIE
;
1503 remove_job(j
, "checkjob");
1508 * Print job status in either short, medium or long format.
1510 * If jobs are compiled in then this routine expects sigchld to be blocked.
1513 j_print(j
, how
, shf
)
1527 if (how
== JP_PGRP
) {
1528 /* POSIX doesn't say what to do it there is no process
1529 * group leader (ie, !FMONITOR). We arbitrarily return
1530 * last pid (which is what $! returns).
1532 shf_fprintf(shf
, "%d\n", j
->pgrp
? j
->pgrp
1533 : (j
->last_proc
? j
->last_proc
->pid
: 0));
1536 j
->flags
&= ~JF_CHANGED
;
1537 filler
= j
->job
> 10 ? "\n " : "\n ";
1540 else if (j
== job_list
->next
)
1543 for (p
= j
->proc_list
; p
!= (Proc
*) 0;) {
1547 strlcpy(buf
, "Running", sizeof buf
);
1550 strlcpy(buf
, sigtraps
[WSTOPSIG(p
->status
)].mess
,
1554 if (how
== JP_SHORT
)
1556 else if (WEXITSTATUS(p
->status
) == 0)
1557 strlcpy(buf
, "Done", sizeof buf
);
1559 shf_snprintf(buf
, sizeof(buf
), "Done (%d)",
1560 WEXITSTATUS(p
->status
));
1563 if (WIFCORED(p
->status
))
1565 /* kludge for not reporting `normal termination signals'
1566 * (ie, SIGINT, SIGPIPE)
1568 if (how
== JP_SHORT
&& !coredumped
1569 && (WTERMSIG(p
->status
) == SIGINT
1570 || WTERMSIG(p
->status
) == SIGPIPE
)) {
1573 strlcpy(buf
, sigtraps
[WTERMSIG(p
->status
)].mess
,
1578 if (how
!= JP_SHORT
) {
1579 if (p
== j
->proc_list
)
1580 shf_fprintf(shf
, "[%d] %c ", j
->job
, jobchar
);
1582 shf_fprintf(shf
, "%s", filler
);
1586 shf_fprintf(shf
, "%5d ", p
->pid
);
1588 if (how
== JP_SHORT
) {
1591 shf_fprintf(shf
, "%s%s ",
1592 buf
, coredumped
? " (core dumped)" : null
);
1596 shf_fprintf(shf
, "%-20s %s%s%s", buf
, p
->command
,
1597 p
->next
? "|" : null
,
1598 coredumped
? " (core dumped)" : null
);
1604 while (p
&& p
->state
== state
1605 && WSTATUS(p
->status
) == WSTATUS(status
))
1608 shf_fprintf(shf
, "%s%5d %-20s %s%s", filler
, p
->pid
,
1609 space
, p
->command
, p
->next
? "|" : null
);
1610 else if (how
== JP_MEDIUM
)
1611 shf_fprintf(shf
, " %s%s", p
->command
,
1612 p
->next
? "|" : null
);
1617 shf_fprintf(shf
, newline
);
1620 /* Convert % sequence to job
1622 * If jobs are compiled in then this routine expects sigchld to be blocked.
1625 j_lookup(cp
, ecodep
)
1629 Job
*j
, *last_match
;
1635 /* Look for last_proc->pid (what $! returns) first... */
1636 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1637 if (j
->last_proc
&& j
->last_proc
->pid
== job
)
1639 /* ...then look for process group (this is non-POSIX),
1640 * but should not break anything (so FPOSIX isn't used).
1642 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1643 if (j
->pgrp
&& j
->pgrp
== job
)
1646 *ecodep
= JL_NOSUCH
;
1651 *ecodep
= JL_INVALID
;
1655 case '\0': /* non-standard */
1658 if (job_list
!= (Job
*) 0)
1663 if (job_list
!= (Job
*) 0 && job_list
->next
)
1664 return job_list
->next
;
1667 case '0': case '1': case '2': case '3': case '4':
1668 case '5': case '6': case '7': case '8': case '9':
1670 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1675 case '?': /* %?string */
1676 last_match
= (Job
*) 0;
1677 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1678 for (p
= j
->proc_list
; p
!= (Proc
*) 0; p
= p
->next
)
1679 if (strstr(p
->command
, cp
+1) != (char *) 0) {
1691 default: /* %string */
1693 last_match
= (Job
*) 0;
1694 for (j
= job_list
; j
!= (Job
*) 0; j
= j
->next
)
1695 if (strncmp(cp
, j
->proc_list
->command
, len
) == 0) {
1708 *ecodep
= JL_NOSUCH
;
1712 static Job
*free_jobs
;
1713 static Proc
*free_procs
;
1715 /* allocate a new job and fill in the job number.
1717 * If jobs are compiled in then this routine expects sigchld to be blocked.
1725 if (free_jobs
!= (Job
*) 0) {
1727 free_jobs
= free_jobs
->next
;
1729 newj
= (Job
*) alloc(sizeof(Job
), APERM
);
1731 /* brute force method */
1732 for (i
= 1; ; i
++) {
1733 for (j
= job_list
; j
&& j
->job
!= i
; j
= j
->next
)
1743 /* Allocate new process struct
1745 * If jobs are compiled in then this routine expects sigchld to be blocked.
1752 if (free_procs
!= (Proc
*) 0) {
1754 free_procs
= free_procs
->next
;
1756 p
= (Proc
*) alloc(sizeof(Proc
), APERM
);
1761 /* Take job out of job_list and put old structures into free list.
1762 * Keeps nzombies, last_job and async_job up to date.
1764 * If jobs are compiled in then this routine expects sigchld to be blocked.
1767 remove_job(j
, where
)
1776 for (; curr
!= (Job
*) 0 && curr
!= j
; prev
= &curr
->next
, curr
= *prev
)
1779 internal_errorf(0, "remove_job: job not found (%s)", where
);
1784 /* free up proc structures */
1785 for (p
= j
->proc_list
; p
!= (Proc
*) 0; ) {
1788 tmp
->next
= free_procs
;
1792 if ((j
->flags
& JF_ZOMBIE
) && j
->ppid
== procpid
)
1794 j
->next
= free_jobs
;
1798 last_job
= (Job
*) 0;
1800 async_job
= (Job
*) 0;
1803 /* put j in a particular location (taking it out job_list if it is there
1806 * If jobs are compiled in then this routine expects sigchld to be blocked.
1815 /* Remove job from list (if there) */
1818 for (; curr
&& curr
!= j
; prev
= &curr
->next
, curr
= *prev
)
1829 case PJ_PAST_STOPPED
:
1832 for (; curr
&& curr
->state
== PSTOPPED
; prev
= &curr
->next
,
1841 /* nuke a job (called when unable to start full job).
1843 * If jobs are compiled in then this routine expects sigchld to be blocked.
1853 for (p
= j
->proc_list
; p
!= (Proc
*) 0; p
= p
->next
)
1855 if (kill(p
->pid
, sig
) < 0)