1232633Smp/* $Header: /p/tcsh/cvsroot/tcsh/sh.proc.h,v 3.15 2011/04/14 18:25:25 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.
17100616Smp * 3. Neither the name of the University nor the names of its contributors
1859243Sobrien *    may be used to endorse or promote products derived from this software
1959243Sobrien *    without specific prior written permission.
2059243Sobrien *
2159243Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2259243Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2359243Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2459243Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2559243Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2659243Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2759243Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2859243Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2959243Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3059243Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3159243Sobrien * SUCH DAMAGE.
3259243Sobrien */
3359243Sobrien#ifndef _h_sh_proc
3459243Sobrien#define _h_sh_proc
3559243Sobrien/*
3659243Sobrien * C shell - process structure declarations
3759243Sobrien */
3859243Sobrien
3959243Sobrien/*
4059243Sobrien * Structure for each process the shell knows about:
4159243Sobrien *	allocated and filled by pcreate.
4259243Sobrien *	flushed by pflush; freeing always happens at top level
4359243Sobrien *	    so the interrupt level has less to worry about.
4459243Sobrien *	processes are related to "friends" when in a pipeline;
4559243Sobrien *	    p_friends links makes a circular list of such jobs
4659243Sobrien */
4759243Sobrienstruct process {
4859243Sobrien    struct process *p_next;	/* next in global "proclist" */
4959243Sobrien    struct process *p_friends;	/* next in job list (or self) */
5059243Sobrien    struct directory *p_cwd;	/* cwd of the job (only in head) */
5159243Sobrien    unsigned long p_flags;	/* various job status flags */
5259243Sobrien    unsigned char p_reason;	/* reason for entering this state */
5359243Sobrien    int     p_index;		/* shorthand job index */
54232633Smp    pid_t   p_parentid;		/* parent pid */
5559243Sobrien    pid_t   p_procid;
5659243Sobrien    pid_t   p_jobid;		/* pid of job leader */
5759243Sobrien    /* if a job is stopped/background p_jobid gives its pgrp */
5859243Sobrien#ifdef BSDTIMES
5959243Sobrien    struct timeval p_btime;	/* begin time */
6059243Sobrien    struct timeval p_etime;	/* end time */
6159243Sobrien    struct sysrusage p_rusage;
6259243Sobrien#else				/* BSDTIMES */
6359243Sobrien# ifdef _SEQUENT_
6459243Sobrien    timeval_t p_btime;		/* begin time */
6559243Sobrien    timeval_t p_etime;		/* end time */
6659243Sobrien    struct process_stats p_rusage;
6759243Sobrien# else				/* _SEQUENT_ */
6859243Sobrien#  ifndef POSIX
6959243Sobrien    time_t  p_btime;		/* begin time */
7059243Sobrien    time_t  p_etime;		/* end time */
7159243Sobrien    time_t  p_utime;		/* user time */
7259243Sobrien    time_t  p_stime;		/* system time */
7359243Sobrien#  else	/* POSIX */
7459243Sobrien    clock_t p_btime;		/* begin time */
7559243Sobrien    clock_t p_etime;		/* end time */
7659243Sobrien    clock_t p_utime;		/* user time */
7759243Sobrien    clock_t p_stime;		/* system time */
7859243Sobrien#  endif /* POSIX */
7959243Sobrien# endif /* _SEQUENT_ */
8059243Sobrien#endif /* BSDTIMES */
81195609Smp    Char   *p_command;		/* command */
8259243Sobrien};
8359243Sobrien
8459243Sobrien/* flag values for p_flags */
8559243Sobrien#define	PRUNNING	(1<<0)	/* running */
8659243Sobrien#define	PSTOPPED	(1<<1)	/* stopped */
8759243Sobrien#define	PNEXITED	(1<<2)	/* normally exited */
8859243Sobrien#define	PAEXITED	(1<<3)	/* abnormally exited */
8959243Sobrien#define	PSIGNALED	(1<<4)	/* terminated by a signal != SIGINT */
9059243Sobrien
9159243Sobrien#define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED| \
9259243Sobrien			 PSIGNALED|PINTERRUPTED)
9359243Sobrien#define	PNOTIFY		(1<<5)	/* notify async when done */
9459243Sobrien#define	PTIME		(1<<6)	/* job times should be printed */
9559243Sobrien#define	PAWAITED	(1<<7)	/* top level is waiting for it */
9659243Sobrien#define	PFOREGND	(1<<8)	/* started in shells pgrp */
9759243Sobrien#define	PDUMPED		(1<<9)	/* process dumped core */
9859243Sobrien#define	PDIAG		(1<<10)	/* diagnostic output also piped out */
9959243Sobrien#define	PPOU		(1<<11)	/* piped output */
10059243Sobrien#define	PREPORTED	(1<<12)	/* status has been reported */
10159243Sobrien#define	PINTERRUPTED	(1<<13)	/* job stopped via interrupt signal */
10259243Sobrien#define	PPTIME		(1<<14)	/* time individual process */
10359243Sobrien#define	PNEEDNOTE	(1<<15)	/* notify as soon as practical */
10459243Sobrien#define PBACKQ		(1<<16)	/* Process is `` evaluation */
10559243Sobrien#define PHUP		(1<<17)	/* Process is marked for SIGHUP on exit */
106232633Smp#define PBRACE		(1<<18)	/* Process is {} evaluation */
10759243Sobrien
10859243Sobrien/* defines for arguments to pprint */
10959243Sobrien#define	NUMBER		01
11059243Sobrien#define	NAME		02
11159243Sobrien#define	REASON		04
11259243Sobrien#define	AMPERSAND	010
11359243Sobrien#define	FANCY		020
11459243Sobrien#define	SHELLDIR	040	/* print shell's dir if not the same */
11559243Sobrien#define	JOBDIR		0100	/* print job's dir if not the same */
11659243Sobrien#define	AREASON		0200
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