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