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