11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1991, 1993
31556Srgrimes *	The Regents of the University of California.  All rights reserved.
41556Srgrimes *
51556Srgrimes * This code is derived from software contributed to Berkeley by
61556Srgrimes * Kenneth Almquist.
71556Srgrimes *
81556Srgrimes * Redistribution and use in source and binary forms, with or without
91556Srgrimes * modification, are permitted provided that the following conditions
101556Srgrimes * are met:
111556Srgrimes * 1. Redistributions of source code must retain the above copyright
121556Srgrimes *    notice, this list of conditions and the following disclaimer.
131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141556Srgrimes *    notice, this list of conditions and the following disclaimer in the
151556Srgrimes *    documentation and/or other materials provided with the distribution.
161556Srgrimes * 4. Neither the name of the University nor the names of its contributors
171556Srgrimes *    may be used to endorse or promote products derived from this software
181556Srgrimes *    without specific prior written permission.
191556Srgrimes *
201556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301556Srgrimes * SUCH DAMAGE.
311556Srgrimes *
3217987Speter *	@(#)jobs.h	8.2 (Berkeley) 5/4/95
3350471Speter * $FreeBSD$
341556Srgrimes */
351556Srgrimes
361556Srgrimes/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
371556Srgrimes#define FORK_FG 0
381556Srgrimes#define FORK_BG 1
391556Srgrimes#define FORK_NOJOB 2
401556Srgrimes
4138536Scracauer#include <signal.h>		/* for sig_atomic_t */
421556Srgrimes
431556Srgrimes/*
441556Srgrimes * A job structure contains information about a job.  A job is either a
451556Srgrimes * single process or a set of processes contained in a pipeline.  In the
461556Srgrimes * latter case, pidlist will be non-NULL, and will point to a -1 terminated
471556Srgrimes * array of pids.
481556Srgrimes */
491556Srgrimes
501556Srgrimesstruct procstat {
5128346Ssteve	pid_t pid;		/* process id */
5228346Ssteve	int status;		/* status flags (defined above) */
531556Srgrimes	char *cmd;		/* text of command being run */
541556Srgrimes};
551556Srgrimes
561556Srgrimes
571556Srgrimes/* states */
581556Srgrimes#define JOBSTOPPED 1		/* all procs are stopped */
591556Srgrimes#define JOBDONE 2		/* all procs are completed */
601556Srgrimes
611556Srgrimes
621556Srgrimesstruct job {
631556Srgrimes	struct procstat ps0;	/* status of process */
641556Srgrimes	struct procstat *ps;	/* status or processes when more than one */
651556Srgrimes	short nprocs;		/* number of processes */
66100308Stjr	pid_t pgrp;		/* process group of this job */
671556Srgrimes	char state;		/* true if job is finished */
681556Srgrimes	char used;		/* true if this entry is in used */
691556Srgrimes	char changed;		/* true if status has changed */
70100305Stjr	char foreground;	/* true if running in the foreground */
71209600Sjilles	char remembered;	/* true if $! referenced */
721556Srgrimes#if JOBS
731556Srgrimes	char jobctl;		/* job running under job control */
7497659Stjr	struct job *next;	/* job used after this one */
751556Srgrimes#endif
761556Srgrimes};
771556Srgrimes
78163085Sstefanfenum {
79163085Sstefanf	SHOWJOBS_DEFAULT,	/* job number, status, command */
80163085Sstefanf	SHOWJOBS_VERBOSE,	/* job number, PID, status, command */
81163085Sstefanf	SHOWJOBS_PIDS,		/* PID only */
82163085Sstefanf	SHOWJOBS_PGIDS		/* PID of the group leader only */
83163085Sstefanf};
84163085Sstefanf
851556Srgrimesextern int job_warning;		/* user was warned about stopped jobs */
861556Srgrimes
8790111Simpvoid setjobctl(int);
88163085Sstefanfvoid showjobs(int, int);
8990111Simpstruct job *makejob(union node *, int);
90100308Stjrpid_t forkshell(struct job *, union node *, int);
91230998Sjillespid_t vforkexecshell(struct job *, char **, char **, const char *, int, int []);
9290111Simpint waitforjob(struct job *, int *);
9390111Simpint stoppedjobs(void);
94209600Sjillesint backgndpidset(void);
95209600Sjillespid_t backgndpidval(void);
9690111Simpchar *commandtext(union node *);
971556Srgrimes
981556Srgrimes#if ! JOBS
991556Srgrimes#define setjobctl(on)	/* do nothing */
1001556Srgrimes#endif
101