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