1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*	$NetBSD: jobs.h,v 1.19 2003/11/27 21:16:14 dsl Exp $	*/
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
3dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*-
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Copyright (c) 1991, 1993
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *	The Regents of the University of California.  All rights reserved.
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * This code is derived from software contributed to Berkeley by
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Kenneth Almquist.
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * Redistribution and use in source and binary forms, with or without
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * modification, are permitted provided that the following conditions
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * are met:
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *    documentation and/or other materials provided with the distribution.
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * 3. Neither the name of the University nor the names of its contributors
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *    may be used to endorse or promote products derived from this software
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *    without specific prior written permission.
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * SUCH DAMAGE.
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project *	@(#)jobs.h	8.2 (Berkeley) 5/4/95
35dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
36dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
37dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "output.h"
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* Mode argument to forkshell.  Don't change FORK_FG or FORK_BG. */
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define FORK_FG 0
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define FORK_BG 1
42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define FORK_NOJOB 2
43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
44dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* mode flags for showjob(s) */
45dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_PGID	0x01	/* only show pgid - for jobs -p */
46dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_MULTILINE	0x02	/* one line per process */
47dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_PID	0x04	/* include process pid */
48dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_CHANGED	0x08	/* only jobs whose state has changed */
49dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_SIGNALLED	0x10	/* only if stopped/exited on signal */
50dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_ISSIG	0x20	/* job was signalled */
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	SHOW_NO_FREE	0x40	/* do not free job */
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
55dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * A job structure contains information about a job.  A job is either a
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * single process or a set of processes contained in a pipeline.  In the
57dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * latter case, pidlist will be non-NULL, and will point to a -1 terminated
58dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project * array of pids.
59dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project */
60dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	MAXCMDTEXT	200
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstruct procstat {
63dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	pid_t	pid;		/* process id */
64dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 	int	status;		/* last process status from wait() */
65dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project 	char	cmd[MAXCMDTEXT];/* text of command being run */
66dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
67dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstruct job {
69dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	struct procstat ps0;	/* status of process */
70dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	struct procstat *ps;	/* status or processes when more than one */
71dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int	nprocs;		/* number of processes */
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	pid_t	pgrp;		/* process group of this job */
73dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char	state;
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	JOBRUNNING	0	/* at least one proc running */
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	JOBSTOPPED	1	/* all procs are stopped */
76dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define	JOBDONE		2	/* all procs are completed */
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char	used;		/* true if this entry is in used */
78dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char	changed;	/* true if status has changed */
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if JOBS
80dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	char 	jobctl;		/* job running under job control */
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int	prev_job;	/* previous job index */
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern pid_t backgndpid;	/* pid of last background process */
86dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern int job_warning;		/* user was warned about stopped jobs */
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
88dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid setjobctl(int);
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint fgcmd(int, char **);
90dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint bgcmd(int, char **);
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint jobscmd(int, char **);
92dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid showjobs(struct output *, int);
93dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint waitcmd(int, char **);
94dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint jobidcmd(int, char **);
95dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstruct job *makejob(union node *, int);
96dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint forkshell(struct job *, union node *, int);
97dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid forkchild(struct job *, union node *, int, int);
98dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint forkparent(struct job *, union node *, int, pid_t);
99dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint waitforjob(struct job *);
100dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint stoppedjobs(void);
101dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid commandtext(struct procstat *, union node *);
102dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectint getjobpgrp(const char *);
103dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
104dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ! JOBS
105dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define setjobctl(on)	/* do nothing */
106dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif