1 1.27 kre /* $NetBSD: jobs.h,v 1.27 2024/06/15 05:18:48 kre 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.18 agc * 3. Neither the name of the University nor the names of its contributors 19 1.1 cgd * may be used to endorse or promote products derived from this software 20 1.1 cgd * without specific prior written permission. 21 1.1 cgd * 22 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.1 cgd * SUCH DAMAGE. 33 1.1 cgd * 34 1.8 christos * @(#)jobs.h 8.2 (Berkeley) 5/4/95 35 1.1 cgd */ 36 1.1 cgd 37 1.16 christos #include "output.h" 38 1.16 christos 39 1.1 cgd /* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ 40 1.1 cgd #define FORK_FG 0 41 1.1 cgd #define FORK_BG 1 42 1.1 cgd #define FORK_NOJOB 2 43 1.1 cgd 44 1.16 christos /* mode flags for showjob(s) */ 45 1.16 christos #define SHOW_PGID 0x01 /* only show pgid - for jobs -p */ 46 1.16 christos #define SHOW_MULTILINE 0x02 /* one line per process */ 47 1.16 christos #define SHOW_PID 0x04 /* include process pid */ 48 1.16 christos #define SHOW_CHANGED 0x08 /* only jobs whose state has changed */ 49 1.16 christos #define SHOW_SIGNALLED 0x10 /* only if stopped/exited on signal */ 50 1.16 christos #define SHOW_ISSIG 0x20 /* job was signalled */ 51 1.16 christos #define SHOW_NO_FREE 0x40 /* do not free job */ 52 1.25 christos #define SHOW_PROCTITLE 0x80 /* set the process title */ 53 1.16 christos 54 1.1 cgd 55 1.1 cgd /* 56 1.1 cgd * A job structure contains information about a job. A job is either a 57 1.1 cgd * single process or a set of processes contained in a pipeline. In the 58 1.1 cgd * latter case, pidlist will be non-NULL, and will point to a -1 terminated 59 1.1 cgd * array of pids. 60 1.1 cgd */ 61 1.16 christos #define MAXCMDTEXT 200 62 1.1 cgd 63 1.1 cgd struct procstat { 64 1.16 christos pid_t pid; /* process id */ 65 1.16 christos int status; /* last process status from wait() */ 66 1.16 christos char cmd[MAXCMDTEXT];/* text of command being run */ 67 1.1 cgd }; 68 1.1 cgd 69 1.1 cgd struct job { 70 1.1 cgd struct procstat ps0; /* status of process */ 71 1.1 cgd struct procstat *ps; /* status or processes when more than one */ 72 1.21 kre void *ref; /* temporary reference, used variously */ 73 1.16 christos int nprocs; /* number of processes */ 74 1.16 christos pid_t pgrp; /* process group of this job */ 75 1.16 christos char state; 76 1.16 christos #define JOBRUNNING 0 /* at least one proc running */ 77 1.16 christos #define JOBSTOPPED 1 /* all procs are stopped */ 78 1.16 christos #define JOBDONE 2 /* all procs are completed */ 79 1.16 christos char used; /* true if this entry is in used */ 80 1.26 kre char flags; 81 1.21 kre #define JOBCHANGED 1 /* set if status has changed */ 82 1.21 kre #define JOBWANTED 2 /* set if this is a job being sought */ 83 1.23 kre #define JPIPEFAIL 4 /* set if -o pipefail when job created */ 84 1.1 cgd #if JOBS 85 1.16 christos char jobctl; /* job running under job control */ 86 1.16 christos int prev_job; /* previous job index */ 87 1.1 cgd #endif 88 1.1 cgd }; 89 1.1 cgd 90 1.16 christos extern pid_t backgndpid; /* pid of last background process */ 91 1.5 jtc extern int job_warning; /* user was warned about stopped jobs */ 92 1.1 cgd 93 1.16 christos void setjobctl(int); 94 1.16 christos void showjobs(struct output *, int); 95 1.16 christos struct job *makejob(union node *, int); 96 1.16 christos int forkshell(struct job *, union node *, int); 97 1.16 christos void forkchild(struct job *, union node *, int, int); 98 1.16 christos int forkparent(struct job *, union node *, int, pid_t); 99 1.16 christos int waitforjob(struct job *); 100 1.16 christos int stoppedjobs(void); 101 1.16 christos void commandtext(struct procstat *, union node *); 102 1.16 christos int getjobpgrp(const char *); 103 1.24 kre int anyjobs(void); 104 1.27 kre void jobstarted(struct job *); 105 1.1 cgd 106 1.1 cgd #if ! JOBS 107 1.1 cgd #define setjobctl(on) /* do nothing */ 108 1.1 cgd #endif 109