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