sh.proc.h revision 59243
159243Sobrien/* $Header: /src/pub/tcsh/sh.proc.h,v 3.9 1997/10/27 22:44:32 christos Exp $ */
259243Sobrien/*
359243Sobrien * sh.proc.h: Process data structures and variables
459243Sobrien */
559243Sobrien/*-
659243Sobrien * Copyright (c) 1980, 1991 The Regents of the University of California.
759243Sobrien * All rights reserved.
859243Sobrien *
959243Sobrien * Redistribution and use in source and binary forms, with or without
1059243Sobrien * modification, are permitted provided that the following conditions
1159243Sobrien * are met:
1259243Sobrien * 1. Redistributions of source code must retain the above copyright
1359243Sobrien *    notice, this list of conditions and the following disclaimer.
1459243Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1559243Sobrien *    notice, this list of conditions and the following disclaimer in the
1659243Sobrien *    documentation and/or other materials provided with the distribution.
1759243Sobrien * 3. All advertising materials mentioning features or use of this software
1859243Sobrien *    must display the following acknowledgement:
1959243Sobrien *	This product includes software developed by the University of
2059243Sobrien *	California, Berkeley and its contributors.
2159243Sobrien * 4. Neither the name of the University nor the names of its contributors
2259243Sobrien *    may be used to endorse or promote products derived from this software
2359243Sobrien *    without specific prior written permission.
2459243Sobrien *
2559243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2659243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2759243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2859243Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2959243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3059243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3159243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3259243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3359243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3459243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3559243Sobrien * SUCH DAMAGE.
3659243Sobrien */
3759243Sobrien#ifndef _h_sh_proc
3859243Sobrien#define _h_sh_proc
3959243Sobrien/*
4059243Sobrien * C shell - process structure declarations
4159243Sobrien */
4259243Sobrien
4359243Sobrien/*
4459243Sobrien * Structure for each process the shell knows about:
4559243Sobrien *	allocated and filled by pcreate.
4659243Sobrien *	flushed by pflush; freeing always happens at top level
4759243Sobrien *	    so the interrupt level has less to worry about.
4859243Sobrien *	processes are related to "friends" when in a pipeline;
4959243Sobrien *	    p_friends links makes a circular list of such jobs
5059243Sobrien */
5159243Sobrienstruct process {
5259243Sobrien    struct process *p_next;	/* next in global "proclist" */
5359243Sobrien    struct process *p_friends;	/* next in job list (or self) */
5459243Sobrien    struct directory *p_cwd;	/* cwd of the job (only in head) */
5559243Sobrien    unsigned long p_flags;	/* various job status flags */
5659243Sobrien    unsigned char p_reason;	/* reason for entering this state */
5759243Sobrien    int     p_index;		/* shorthand job index */
5859243Sobrien    pid_t   p_procid;
5959243Sobrien    pid_t   p_jobid;		/* pid of job leader */
6059243Sobrien    /* if a job is stopped/background p_jobid gives its pgrp */
6159243Sobrien#ifdef BSDTIMES
6259243Sobrien    struct timeval p_btime;	/* begin time */
6359243Sobrien    struct timeval p_etime;	/* end time */
6459243Sobrien    struct sysrusage p_rusage;
6559243Sobrien#else				/* BSDTIMES */
6659243Sobrien# ifdef _SEQUENT_
6759243Sobrien    timeval_t p_btime;		/* begin time */
6859243Sobrien    timeval_t p_etime;		/* end time */
6959243Sobrien    struct process_stats p_rusage;
7059243Sobrien# else				/* _SEQUENT_ */
7159243Sobrien#  ifndef POSIX
7259243Sobrien    time_t  p_btime;		/* begin time */
7359243Sobrien    time_t  p_etime;		/* end time */
7459243Sobrien    time_t  p_utime;		/* user time */
7559243Sobrien    time_t  p_stime;		/* system time */
7659243Sobrien#  else	/* POSIX */
7759243Sobrien    clock_t p_btime;		/* begin time */
7859243Sobrien    clock_t p_etime;		/* end time */
7959243Sobrien    clock_t p_utime;		/* user time */
8059243Sobrien    clock_t p_stime;		/* system time */
8159243Sobrien#  endif /* POSIX */
8259243Sobrien# endif /* _SEQUENT_ */
8359243Sobrien#endif /* BSDTIMES */
8459243Sobrien    Char   *p_command;		/* first PMAXLEN chars of command */
8559243Sobrien};
8659243Sobrien
8759243Sobrien/* flag values for p_flags */
8859243Sobrien#define	PRUNNING	(1<<0)	/* running */
8959243Sobrien#define	PSTOPPED	(1<<1)	/* stopped */
9059243Sobrien#define	PNEXITED	(1<<2)	/* normally exited */
9159243Sobrien#define	PAEXITED	(1<<3)	/* abnormally exited */
9259243Sobrien#define	PSIGNALED	(1<<4)	/* terminated by a signal != SIGINT */
9359243Sobrien
9459243Sobrien#define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED| \
9559243Sobrien			 PSIGNALED|PINTERRUPTED)
9659243Sobrien#define	PNOTIFY		(1<<5)	/* notify async when done */
9759243Sobrien#define	PTIME		(1<<6)	/* job times should be printed */
9859243Sobrien#define	PAWAITED	(1<<7)	/* top level is waiting for it */
9959243Sobrien#define	PFOREGND	(1<<8)	/* started in shells pgrp */
10059243Sobrien#define	PDUMPED		(1<<9)	/* process dumped core */
10159243Sobrien#define	PDIAG		(1<<10)	/* diagnostic output also piped out */
10259243Sobrien#define	PPOU		(1<<11)	/* piped output */
10359243Sobrien#define	PREPORTED	(1<<12)	/* status has been reported */
10459243Sobrien#define	PINTERRUPTED	(1<<13)	/* job stopped via interrupt signal */
10559243Sobrien#define	PPTIME		(1<<14)	/* time individual process */
10659243Sobrien#define	PNEEDNOTE	(1<<15)	/* notify as soon as practical */
10759243Sobrien#define PBACKQ		(1<<16)	/* Process is `` evaluation */
10859243Sobrien#define PHUP		(1<<17)	/* Process is marked for SIGHUP on exit */
10959243Sobrien
11059243Sobrien#define	PMAXLEN		80
11159243Sobrien
11259243Sobrien/* defines for arguments to pprint */
11359243Sobrien#define	NUMBER		01
11459243Sobrien#define	NAME		02
11559243Sobrien#define	REASON		04
11659243Sobrien#define	AMPERSAND	010
11759243Sobrien#define	FANCY		020
11859243Sobrien#define	SHELLDIR	040	/* print shell's dir if not the same */
11959243Sobrien#define	JOBDIR		0100	/* print job's dir if not the same */
12059243Sobrien#define	AREASON		0200
12159243Sobrien
12259243SobrienEXTERN struct process proclist IZERO_STRUCT;/* list head of all processes */
12359243SobrienEXTERN bool    pnoprocesses IZERO;	/* pchild found nothing to wait for */
12459243Sobrien
12559243SobrienEXTERN struct process *pholdjob IZERO;	/* one level stack of current jobs */
12659243Sobrien
12759243SobrienEXTERN struct process *pcurrjob IZERO;	/* current job */
12859243SobrienEXTERN struct process *pcurrent IZERO;	/* current job in table */
12959243SobrienEXTERN struct process *pprevious IZERO;	/* previous job in table */
13059243Sobrien
13159243SobrienEXTERN int   pmaxindex IZERO;		/* current maximum job index */
13259243Sobrien
13359243Sobrien#ifndef BSDTIMES
13459243SobrienEXTERN bool    timesdone;	/* shtimes buffer full ? */
13559243Sobrien#endif /* BSDTIMES */
13659243Sobrien
13759243Sobrien#endif /* _h_sh_proc */
138