xref: /original-bsd/bin/csh/proc.h (revision ba762ddc)
1 /*-
2  * Copyright (c) 1980, 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)proc.h	5.3 (Berkeley) 04/04/91
8  */
9 
10 /*
11  * C shell - process structure declarations
12  */
13 
14 /*
15  * Structure for each process the shell knows about:
16  *	allocated and filled by pcreate.
17  *	flushed by pflush; freeing always happens at top level
18  *	    so the interrupt level has less to worry about.
19  *	processes are related to "friends" when in a pipeline;
20  *	    p_friends links makes a circular list of such jobs
21  */
22 struct process	{
23 	struct	process *p_next;	/* next in global "proclist" */
24 	struct	process	*p_friends;	/* next in job list (or self) */
25 	struct	directory *p_cwd;	/* cwd of the job (only in head) */
26 	short	unsigned p_flags;	/* various job status flags */
27 	char	p_reason;		/* reason for entering this state */
28 	char	p_index;		/* shorthand job index */
29 	int	p_pid;
30 	int	p_jobid;		/* pid of job leader */
31 	/* if a job is stopped/background p_jobid gives its pgrp */
32 	struct	timeval p_btime;	/* begin time */
33 	struct	timeval p_etime;	/* end time */
34 	struct	rusage p_rusage;
35 	char	*p_command;		/* first PMAXLEN chars of command */
36 };
37 
38 /* flag values for p_flags */
39 #define	PRUNNING	(1<<0)		/* running */
40 #define	PSTOPPED	(1<<1)		/* stopped */
41 #define	PNEXITED	(1<<2)		/* normally exited */
42 #define	PAEXITED	(1<<3)		/* abnormally exited */
43 #define	PSIGNALED	(1<<4)		/* terminated by a signal != SIGINT */
44 
45 #define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED|PSIGNALED|PINTERRUPTED)
46 #define	PNOTIFY		(1<<5)		/* notify async when done */
47 #define	PTIME		(1<<6)		/* job times should be printed */
48 #define	PAWAITED	(1<<7)		/* top level is waiting for it */
49 #define	PFOREGND	(1<<8)		/* started in shells pgrp */
50 #define	PDUMPED		(1<<9)		/* process dumped core */
51 #define	PDIAG		(1<<10)		/* diagnostic output also piped out */
52 #define	PPOU		(1<<11)		/* piped output */
53 #define	PREPORTED	(1<<12)		/* status has been reported */
54 #define	PINTERRUPTED	(1<<13)		/* job stopped via interrupt signal */
55 #define	PPTIME		(1<<14)		/* time individual process */
56 #define	PNEEDNOTE	(1<<15)		/* notify as soon as practical */
57 
58 #define	PNULL		(struct process *)0
59 #define	PMAXLEN		80
60 
61 /* defines for arguments to pprint */
62 #define	NUMBER		01
63 #define	NAME		02
64 #define	REASON		04
65 #define	AMPERSAND	010
66 #define	FANCY		020
67 #define	SHELLDIR	040		/* print shell's dir if not the same */
68 #define	JOBDIR		0100		/* print job's dir if not the same */
69 #define	AREASON		0200
70 
71 struct	process	proclist;		/* list head of all processes */
72 bool	pnoprocesses;			/* pchild found nothing to wait for */
73 
74 struct	process *pholdjob;		/* one level stack of current jobs */
75 
76 struct	process *pcurrjob;		/* current job */
77 struct	process	*pcurrent;		/* current job in table */
78 struct	process *pprevious;		/* previous job in table */
79 
80 short	pmaxindex;			/* current maximum job index */
81 
82 int	psigint();
83 struct	process	*pgetcurr();
84 struct	process	*plookup();
85 struct	process *pfind();
86