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