jobs.h revision 209600
1251881Speter/*-
2251881Speter * Copyright (c) 1991, 1993
3251881Speter *	The Regents of the University of California.  All rights reserved.
4251881Speter *
5251881Speter * This code is derived from software contributed to Berkeley by
6251881Speter * Kenneth Almquist.
7251881Speter *
8251881Speter * Redistribution and use in source and binary forms, with or without
9251881Speter * modification, are permitted provided that the following conditions
10251881Speter * are met:
11251881Speter * 1. Redistributions of source code must retain the above copyright
12251881Speter *    notice, this list of conditions and the following disclaimer.
13251881Speter * 2. Redistributions in binary form must reproduce the above copyright
14251881Speter *    notice, this list of conditions and the following disclaimer in the
15251881Speter *    documentation and/or other materials provided with the distribution.
16251881Speter * 4. Neither the name of the University nor the names of its contributors
17251881Speter *    may be used to endorse or promote products derived from this software
18251881Speter *    without specific prior written permission.
19251881Speter *
20251881Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21251881Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22251881Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23251881Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24251881Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25251881Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26251881Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27251881Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28251881Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29251881Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30251881Speter * SUCH DAMAGE.
31251881Speter *
32251881Speter *	@(#)jobs.h	8.2 (Berkeley) 5/4/95
33251881Speter * $FreeBSD: head/bin/sh/jobs.h 209600 2010-06-29 22:37:45Z jilles $
34251881Speter */
35251881Speter
36251881Speter/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
37251881Speter#define FORK_FG 0
38251881Speter#define FORK_BG 1
39251881Speter#define FORK_NOJOB 2
40251881Speter
41251881Speter#include <signal.h>		/* for sig_atomic_t */
42251881Speter
43251881Speter/*
44251881Speter * A job structure contains information about a job.  A job is either a
45251881Speter * single process or a set of processes contained in a pipeline.  In the
46251881Speter * latter case, pidlist will be non-NULL, and will point to a -1 terminated
47251881Speter * array of pids.
48251881Speter */
49251881Speter
50251881Speterstruct procstat {
51251881Speter	pid_t pid;		/* process id */
52251881Speter	int status;		/* status flags (defined above) */
53251881Speter	char *cmd;		/* text of command being run */
54251881Speter};
55251881Speter
56251881Speter
57251881Speter/* states */
58251881Speter#define JOBSTOPPED 1		/* all procs are stopped */
59251881Speter#define JOBDONE 2		/* all procs are completed */
60251881Speter
61251881Speter
62251881Speterstruct job {
63251881Speter	struct procstat ps0;	/* status of process */
64251881Speter	struct procstat *ps;	/* status or processes when more than one */
65251881Speter	short nprocs;		/* number of processes */
66251881Speter	pid_t pgrp;		/* process group of this job */
67251881Speter	char state;		/* true if job is finished */
68251881Speter	char used;		/* true if this entry is in used */
69251881Speter	char changed;		/* true if status has changed */
70251881Speter	char foreground;	/* true if running in the foreground */
71251881Speter	char remembered;	/* true if $! referenced */
72251881Speter#if JOBS
73251881Speter	char jobctl;		/* job running under job control */
74251881Speter	struct job *next;	/* job used after this one */
75251881Speter#endif
76251881Speter};
77251881Speter
78251881Speterenum {
79251881Speter	SHOWJOBS_DEFAULT,	/* job number, status, command */
80251881Speter	SHOWJOBS_VERBOSE,	/* job number, PID, status, command */
81251881Speter	SHOWJOBS_PIDS,		/* PID only */
82251881Speter	SHOWJOBS_PGIDS		/* PID of the group leader only */
83251881Speter};
84251881Speter
85251881Speterextern int job_warning;		/* user was warned about stopped jobs */
86251881Speterextern int in_waitcmd;		/* are we in waitcmd()? */
87251881Speterextern int in_dowait;		/* are we in dowait()? */
88251881Speterextern volatile sig_atomic_t breakwaitcmd; /* break wait to process traps? */
89251881Speter
90251881Spetervoid setjobctl(int);
91251881Speterint fgcmd(int, char **);
92251881Speterint bgcmd(int, char **);
93251881Speterint jobscmd(int, char **);
94251881Spetervoid showjobs(int, int);
95251881Speterint waitcmd(int, char **);
96251881Speterint jobidcmd(int, char **);
97251881Speterstruct job *makejob(union node *, int);
98251881Speterpid_t forkshell(struct job *, union node *, int);
99251881Speterint waitforjob(struct job *, int *);
100251881Speterint stoppedjobs(void);
101251881Speterint backgndpidset(void);
102251881Speterpid_t backgndpidval(void);
103251881Speterchar *commandtext(union node *);
104251881Speter
105251881Speter#if ! JOBS
106251881Speter#define setjobctl(on)	/* do nothing */
107251881Speter#endif
108251881Speter