xref: /freebsd/contrib/tcsh/sh.proc.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1 /*
2  * sh.proc.h: Process data structures and variables
3  */
4 /*-
5  * Copyright (c) 1980, 1991 The Regents of the University of California.
6  * 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 #ifndef _h_sh_proc
33 #define _h_sh_proc
34 /*
35  * C shell - process structure declarations
36  */
37 
38 /*
39  * Structure for each process the shell knows about:
40  *	allocated and filled by pcreate.
41  *	flushed by pflush; freeing always happens at top level
42  *	    so the interrupt level has less to worry about.
43  *	processes are related to "friends" when in a pipeline;
44  *	    p_friends links makes a circular list of such jobs
45  */
46 struct process {
47     struct process *p_next;	/* next in global "proclist" */
48     struct process *p_friends;	/* next in job list (or self) */
49     struct directory *p_cwd;	/* cwd of the job (only in head) */
50     unsigned long p_flags;	/* various job status flags */
51     unsigned char p_reason;	/* reason for entering this state */
52     int     p_index;		/* shorthand job index */
53     pid_t   p_parentid;		/* parent pid */
54     pid_t   p_procid;
55     pid_t   p_jobid;		/* pid of job leader */
56     /* if a job is stopped/background p_jobid gives its pgrp */
57 #ifdef BSDTIMES
58     struct timeval p_btime;	/* begin time */
59     struct timeval p_etime;	/* end time */
60     struct sysrusage p_rusage;
61 #else				/* BSDTIMES */
62 # ifdef _SEQUENT_
63     timeval_t p_btime;		/* begin time */
64     timeval_t p_etime;		/* end time */
65     struct process_stats p_rusage;
66 # else				/* _SEQUENT_ */
67 #  ifndef POSIX
68     time_t  p_btime;		/* begin time */
69     time_t  p_etime;		/* end time */
70     time_t  p_utime;		/* user time */
71     time_t  p_stime;		/* system time */
72 #  else	/* POSIX */
73     clock_t p_btime;		/* begin time */
74     clock_t p_etime;		/* end time */
75     clock_t p_utime;		/* user time */
76     clock_t p_stime;		/* system time */
77 #  endif /* POSIX */
78 # endif /* _SEQUENT_ */
79 #endif /* BSDTIMES */
80     Char   *p_command;		/* command */
81 };
82 
83 /* flag values for p_flags */
84 #define	PRUNNING	(1<<0)	/* running */
85 #define	PSTOPPED	(1<<1)	/* stopped */
86 #define	PNEXITED	(1<<2)	/* normally exited */
87 #define	PAEXITED	(1<<3)	/* abnormally exited */
88 #define	PSIGNALED	(1<<4)	/* terminated by a signal != SIGINT */
89 
90 #define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED| \
91 			 PSIGNALED|PINTERRUPTED)
92 #define	PNOTIFY		(1<<5)	/* notify async when done */
93 #define	PTIME		(1<<6)	/* job times should be printed */
94 #define	PAWAITED	(1<<7)	/* top level is waiting for it */
95 #define	PFOREGND	(1<<8)	/* started in shells pgrp */
96 #define	PDUMPED		(1<<9)	/* process dumped core */
97 #define	PDIAG		(1<<10)	/* diagnostic output also piped out */
98 #define	PPOU		(1<<11)	/* piped output */
99 #define	PREPORTED	(1<<12)	/* status has been reported */
100 #define	PINTERRUPTED	(1<<13)	/* job stopped via interrupt signal */
101 #define	PPTIME		(1<<14)	/* time individual process */
102 #define	PNEEDNOTE	(1<<15)	/* notify as soon as practical */
103 #define PBACKQ		(1<<16)	/* Process is `` evaluation */
104 #define PHUP		(1<<17)	/* Process is marked for SIGHUP on exit */
105 #define PBRACE		(1<<18)	/* Process is {} evaluation */
106 
107 /* defines for arguments to pprint */
108 #define	NUMBER		0x001
109 #define	NAME		0x002
110 #define	REASON		0x004
111 #define	AMPERSAND	0x008
112 #define	FANCY		0x010
113 #define	SHELLDIR	0x020	/* print shell's dir if not the same */
114 #define	JOBDIR		0x040	/* print job's dir if not the same */
115 #define	AREASON		0x080
116 #define	JOBLIST		0x100
117 
118 EXTERN struct process proclist IZERO_STRUCT;/* list head of all processes */
119 
120 EXTERN struct process *pholdjob IZERO;	/* one level stack of current jobs */
121 
122 EXTERN struct process *pcurrjob IZERO;	/* current job */
123 EXTERN struct process *pcurrent IZERO;	/* current job in table */
124 EXTERN struct process *pprevious IZERO;	/* previous job in table */
125 
126 EXTERN int   pmaxindex IZERO;		/* current maximum job index */
127 
128 #endif /* _h_sh_proc */
129