sh.proc.h revision 231990
1218799Snwhitehorn/* $Header: /p/tcsh/cvsroot/tcsh/sh.proc.h,v 3.15 2011/04/14 18:25:25 christos Exp $ */
2218799Snwhitehorn/*
3218799Snwhitehorn * sh.proc.h: Process data structures and variables
4218799Snwhitehorn */
5218799Snwhitehorn/*-
6218799Snwhitehorn * Copyright (c) 1980, 1991 The Regents of the University of California.
7218799Snwhitehorn * All rights reserved.
8218799Snwhitehorn *
9218799Snwhitehorn * Redistribution and use in source and binary forms, with or without
10218799Snwhitehorn * modification, are permitted provided that the following conditions
11218799Snwhitehorn * are met:
12218799Snwhitehorn * 1. Redistributions of source code must retain the above copyright
13218799Snwhitehorn *    notice, this list of conditions and the following disclaimer.
14218799Snwhitehorn * 2. Redistributions in binary form must reproduce the above copyright
15218799Snwhitehorn *    notice, this list of conditions and the following disclaimer in the
16218799Snwhitehorn *    documentation and/or other materials provided with the distribution.
17218799Snwhitehorn * 3. Neither the name of the University nor the names of its contributors
18218799Snwhitehorn *    may be used to endorse or promote products derived from this software
19218799Snwhitehorn *    without specific prior written permission.
20218799Snwhitehorn *
21218799Snwhitehorn * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22218799Snwhitehorn * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23218799Snwhitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24218799Snwhitehorn * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25218799Snwhitehorn * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26218799Snwhitehorn * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27218799Snwhitehorn * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28218799Snwhitehorn * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29218799Snwhitehorn * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30218799Snwhitehorn * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31218799Snwhitehorn * SUCH DAMAGE.
32218799Snwhitehorn */
33218799Snwhitehorn#ifndef _h_sh_proc
34218799Snwhitehorn#define _h_sh_proc
35330980Seadler/*
36218799Snwhitehorn * C shell - process structure declarations
37225065Snwhitehorn */
38
39/*
40 * Structure for each process the shell knows about:
41 *	allocated and filled by pcreate.
42 *	flushed by pflush; freeing always happens at top level
43 *	    so the interrupt level has less to worry about.
44 *	processes are related to "friends" when in a pipeline;
45 *	    p_friends links makes a circular list of such jobs
46 */
47struct process {
48    struct process *p_next;	/* next in global "proclist" */
49    struct process *p_friends;	/* next in job list (or self) */
50    struct directory *p_cwd;	/* cwd of the job (only in head) */
51    unsigned long p_flags;	/* various job status flags */
52    unsigned char p_reason;	/* reason for entering this state */
53    int     p_index;		/* shorthand job index */
54    pid_t   p_parentid;		/* parent pid */
55    pid_t   p_procid;
56    pid_t   p_jobid;		/* pid of job leader */
57    /* if a job is stopped/background p_jobid gives its pgrp */
58#ifdef BSDTIMES
59    struct timeval p_btime;	/* begin time */
60    struct timeval p_etime;	/* end time */
61    struct sysrusage p_rusage;
62#else				/* BSDTIMES */
63# ifdef _SEQUENT_
64    timeval_t p_btime;		/* begin time */
65    timeval_t p_etime;		/* end time */
66    struct process_stats p_rusage;
67# else				/* _SEQUENT_ */
68#  ifndef POSIX
69    time_t  p_btime;		/* begin time */
70    time_t  p_etime;		/* end time */
71    time_t  p_utime;		/* user time */
72    time_t  p_stime;		/* system time */
73#  else	/* POSIX */
74    clock_t p_btime;		/* begin time */
75    clock_t p_etime;		/* end time */
76    clock_t p_utime;		/* user time */
77    clock_t p_stime;		/* system time */
78#  endif /* POSIX */
79# endif /* _SEQUENT_ */
80#endif /* BSDTIMES */
81    Char   *p_command;		/* command */
82};
83
84/* flag values for p_flags */
85#define	PRUNNING	(1<<0)	/* running */
86#define	PSTOPPED	(1<<1)	/* stopped */
87#define	PNEXITED	(1<<2)	/* normally exited */
88#define	PAEXITED	(1<<3)	/* abnormally exited */
89#define	PSIGNALED	(1<<4)	/* terminated by a signal != SIGINT */
90
91#define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED| \
92			 PSIGNALED|PINTERRUPTED)
93#define	PNOTIFY		(1<<5)	/* notify async when done */
94#define	PTIME		(1<<6)	/* job times should be printed */
95#define	PAWAITED	(1<<7)	/* top level is waiting for it */
96#define	PFOREGND	(1<<8)	/* started in shells pgrp */
97#define	PDUMPED		(1<<9)	/* process dumped core */
98#define	PDIAG		(1<<10)	/* diagnostic output also piped out */
99#define	PPOU		(1<<11)	/* piped output */
100#define	PREPORTED	(1<<12)	/* status has been reported */
101#define	PINTERRUPTED	(1<<13)	/* job stopped via interrupt signal */
102#define	PPTIME		(1<<14)	/* time individual process */
103#define	PNEEDNOTE	(1<<15)	/* notify as soon as practical */
104#define PBACKQ		(1<<16)	/* Process is `` evaluation */
105#define PHUP		(1<<17)	/* Process is marked for SIGHUP on exit */
106#define PBRACE		(1<<18)	/* Process is {} evaluation */
107
108/* defines for arguments to pprint */
109#define	NUMBER		01
110#define	NAME		02
111#define	REASON		04
112#define	AMPERSAND	010
113#define	FANCY		020
114#define	SHELLDIR	040	/* print shell's dir if not the same */
115#define	JOBDIR		0100	/* print job's dir if not the same */
116#define	AREASON		0200
117
118EXTERN struct process proclist IZERO_STRUCT;/* list head of all processes */
119
120EXTERN struct process *pholdjob IZERO;	/* one level stack of current jobs */
121
122EXTERN struct process *pcurrjob IZERO;	/* current job */
123EXTERN struct process *pcurrent IZERO;	/* current job in table */
124EXTERN struct process *pprevious IZERO;	/* previous job in table */
125
126EXTERN int   pmaxindex IZERO;		/* current maximum job index */
127
128#endif /* _h_sh_proc */
129