1*d1e4d7ceSDavid van Moolenbroek /* $NetBSD: proc.h,v 1.14 2013/07/16 17:47:43 christos Exp $ */ 2*d1e4d7ceSDavid van Moolenbroek 3*d1e4d7ceSDavid van Moolenbroek /*- 4*d1e4d7ceSDavid van Moolenbroek * Copyright (c) 1980, 1991, 1993 5*d1e4d7ceSDavid van Moolenbroek * The Regents of the University of California. All rights reserved. 6*d1e4d7ceSDavid van Moolenbroek * 7*d1e4d7ceSDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without 8*d1e4d7ceSDavid van Moolenbroek * modification, are permitted provided that the following conditions 9*d1e4d7ceSDavid van Moolenbroek * are met: 10*d1e4d7ceSDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright 11*d1e4d7ceSDavid van Moolenbroek * notice, this list of conditions and the following disclaimer. 12*d1e4d7ceSDavid van Moolenbroek * 2. Redistributions in binary form must reproduce the above copyright 13*d1e4d7ceSDavid van Moolenbroek * notice, this list of conditions and the following disclaimer in the 14*d1e4d7ceSDavid van Moolenbroek * documentation and/or other materials provided with the distribution. 15*d1e4d7ceSDavid van Moolenbroek * 3. Neither the name of the University nor the names of its contributors 16*d1e4d7ceSDavid van Moolenbroek * may be used to endorse or promote products derived from this software 17*d1e4d7ceSDavid van Moolenbroek * without specific prior written permission. 18*d1e4d7ceSDavid van Moolenbroek * 19*d1e4d7ceSDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20*d1e4d7ceSDavid van Moolenbroek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21*d1e4d7ceSDavid van Moolenbroek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22*d1e4d7ceSDavid van Moolenbroek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23*d1e4d7ceSDavid van Moolenbroek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24*d1e4d7ceSDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25*d1e4d7ceSDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26*d1e4d7ceSDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27*d1e4d7ceSDavid van Moolenbroek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28*d1e4d7ceSDavid van Moolenbroek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29*d1e4d7ceSDavid van Moolenbroek * SUCH DAMAGE. 30*d1e4d7ceSDavid van Moolenbroek * 31*d1e4d7ceSDavid van Moolenbroek * @(#)proc.h 8.1 (Berkeley) 5/31/93 32*d1e4d7ceSDavid van Moolenbroek */ 33*d1e4d7ceSDavid van Moolenbroek 34*d1e4d7ceSDavid van Moolenbroek #ifndef _PROC_H_ 35*d1e4d7ceSDavid van Moolenbroek #define _PROC_H_ 36*d1e4d7ceSDavid van Moolenbroek 37*d1e4d7ceSDavid van Moolenbroek /* 38*d1e4d7ceSDavid van Moolenbroek * Structure for each process the shell knows about: 39*d1e4d7ceSDavid van Moolenbroek * allocated and filled by pcreate. 40*d1e4d7ceSDavid van Moolenbroek * flushed by pflush; freeing always happens at top level 41*d1e4d7ceSDavid van Moolenbroek * so the interrupt level has less to worry about. 42*d1e4d7ceSDavid van Moolenbroek * processes are related to "friends" when in a pipeline; 43*d1e4d7ceSDavid van Moolenbroek * p_friends links makes a circular list of such jobs 44*d1e4d7ceSDavid van Moolenbroek */ 45*d1e4d7ceSDavid van Moolenbroek struct process { 46*d1e4d7ceSDavid van Moolenbroek struct process *p_next; /* next in global "proclist" */ 47*d1e4d7ceSDavid van Moolenbroek struct process *p_friends; /* next in job list (or self) */ 48*d1e4d7ceSDavid van Moolenbroek struct directory *p_cwd; /* cwd of the job (only in head) */ 49*d1e4d7ceSDavid van Moolenbroek int p_flags; /* various job status flags */ 50*d1e4d7ceSDavid van Moolenbroek int p_reason; /* reason for entering this state */ 51*d1e4d7ceSDavid van Moolenbroek int p_index; /* shorthand job index */ 52*d1e4d7ceSDavid van Moolenbroek pid_t p_pid; 53*d1e4d7ceSDavid van Moolenbroek pid_t p_jobid; /* pid of job leader */ 54*d1e4d7ceSDavid van Moolenbroek /* if a job is stopped/background p_jobid gives its pgrp */ 55*d1e4d7ceSDavid van Moolenbroek struct timespec p_btime; /* begin time */ 56*d1e4d7ceSDavid van Moolenbroek struct timespec p_etime; /* end time */ 57*d1e4d7ceSDavid van Moolenbroek struct rusage p_rusage; 58*d1e4d7ceSDavid van Moolenbroek Char *p_command; /* first PMAXLEN chars of command */ 59*d1e4d7ceSDavid van Moolenbroek }; 60*d1e4d7ceSDavid van Moolenbroek 61*d1e4d7ceSDavid van Moolenbroek /* flag values for p_flags */ 62*d1e4d7ceSDavid van Moolenbroek #define PRUNNING (1<<0) /* running */ 63*d1e4d7ceSDavid van Moolenbroek #define PSTOPPED (1<<1) /* stopped */ 64*d1e4d7ceSDavid van Moolenbroek #define PNEXITED (1<<2) /* normally exited */ 65*d1e4d7ceSDavid van Moolenbroek #define PAEXITED (1<<3) /* abnormally exited */ 66*d1e4d7ceSDavid van Moolenbroek #define PSIGNALED (1<<4) /* terminated by a signal != SIGINT */ 67*d1e4d7ceSDavid van Moolenbroek #define PNOTIFY (1<<5) /* notify async when done */ 68*d1e4d7ceSDavid van Moolenbroek #define PTIME (1<<6) /* job times should be printed */ 69*d1e4d7ceSDavid van Moolenbroek #define PAWAITED (1<<7) /* top level is waiting for it */ 70*d1e4d7ceSDavid van Moolenbroek #define PFOREGND (1<<8) /* started in shells pgrp */ 71*d1e4d7ceSDavid van Moolenbroek #define PDUMPED (1<<9) /* process dumped core */ 72*d1e4d7ceSDavid van Moolenbroek #define PERR (1<<10) /* diagnostic output also piped out */ 73*d1e4d7ceSDavid van Moolenbroek #define PPOU (1<<11) /* piped output */ 74*d1e4d7ceSDavid van Moolenbroek #define PREPORTED (1<<12) /* status has been reported */ 75*d1e4d7ceSDavid van Moolenbroek #define PINTERRUPTED (1<<13) /* job stopped via interrupt signal */ 76*d1e4d7ceSDavid van Moolenbroek #define PPTIME (1<<14) /* time individual process */ 77*d1e4d7ceSDavid van Moolenbroek #define PNEEDNOTE (1<<15) /* notify as soon as practical */ 78*d1e4d7ceSDavid van Moolenbroek 79*d1e4d7ceSDavid van Moolenbroek #define PALLSTATES (PRUNNING|PSTOPPED|PNEXITED|PAEXITED|PSIGNALED|PINTERRUPTED) 80*d1e4d7ceSDavid van Moolenbroek 81*d1e4d7ceSDavid van Moolenbroek #define PMAXLEN 80 82*d1e4d7ceSDavid van Moolenbroek 83*d1e4d7ceSDavid van Moolenbroek /* defines for arguments to pprint */ 84*d1e4d7ceSDavid van Moolenbroek #define NUMBER 01 85*d1e4d7ceSDavid van Moolenbroek #define NAME 02 86*d1e4d7ceSDavid van Moolenbroek #define REASON 04 87*d1e4d7ceSDavid van Moolenbroek #define AMPERSAND 010 88*d1e4d7ceSDavid van Moolenbroek #define FANCY 020 89*d1e4d7ceSDavid van Moolenbroek #define SHELLDIR 040 /* print shell's dir if not the same */ 90*d1e4d7ceSDavid van Moolenbroek #define JOBDIR 0100 /* print job's dir if not the same */ 91*d1e4d7ceSDavid van Moolenbroek #define AREASON 0200 92*d1e4d7ceSDavid van Moolenbroek 93*d1e4d7ceSDavid van Moolenbroek struct process proclist; /* list head of all processes */ 94*d1e4d7ceSDavid van Moolenbroek int pnoprocesses; /* pchild found nothing to wait for */ 95*d1e4d7ceSDavid van Moolenbroek 96*d1e4d7ceSDavid van Moolenbroek struct process *pholdjob; /* one level stack of current jobs */ 97*d1e4d7ceSDavid van Moolenbroek 98*d1e4d7ceSDavid van Moolenbroek struct process *pcurrjob; /* current job */ 99*d1e4d7ceSDavid van Moolenbroek struct process *pcurrent; /* current job in table */ 100*d1e4d7ceSDavid van Moolenbroek struct process *pprevious; /* previous job in table */ 101*d1e4d7ceSDavid van Moolenbroek 102*d1e4d7ceSDavid van Moolenbroek int pmaxindex; /* current maximum job index */ 103*d1e4d7ceSDavid van Moolenbroek 104*d1e4d7ceSDavid van Moolenbroek #endif /* !_PROC_H_ */ 105