xref: /illumos-gate/usr/src/cmd/csh/sh.proc.h (revision 6c02b4a4b46fecc2fa6bf1ab6b5e3255ad1d0767)
17c478bd9Sstevel@tonic-gate /*
2*6c02b4a4Smuffin  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley Software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate /*
187c478bd9Sstevel@tonic-gate  * C shell - process structure declarations
197c478bd9Sstevel@tonic-gate  */
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate /*
227c478bd9Sstevel@tonic-gate  * Structure for each process the shell knows about:
237c478bd9Sstevel@tonic-gate  *	allocated and filled by pcreate.
247c478bd9Sstevel@tonic-gate  *	flushed by pflush; freeing always happens at top level
257c478bd9Sstevel@tonic-gate  *	    so the interrupt level has less to worry about.
267c478bd9Sstevel@tonic-gate  *	processes are related to "friends" when in a pipeline;
277c478bd9Sstevel@tonic-gate  *	    p_friends links makes a circular list of such jobs
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate struct process	{
307c478bd9Sstevel@tonic-gate 	struct	process *p_next;	/* next in global "proclist" */
317c478bd9Sstevel@tonic-gate 	struct	process	*p_friends;	/* next in job list (or self) */
327c478bd9Sstevel@tonic-gate 	struct	directory *p_cwd;	/* cwd of the job (only in head) */
337c478bd9Sstevel@tonic-gate 	short	unsigned p_flags;	/* various job status flags */
347c478bd9Sstevel@tonic-gate  tchar p_reason;		/* reason for entering this state */
357c478bd9Sstevel@tonic-gate  tchar p_index;		/* shorthand job index */
367c478bd9Sstevel@tonic-gate 	int	p_pid;
377c478bd9Sstevel@tonic-gate 	int	p_jobid;		/* pid of job leader */
387c478bd9Sstevel@tonic-gate 	/* if a job is stopped/background p_jobid gives its pgrp */
397c478bd9Sstevel@tonic-gate 	struct	timeval p_btime;	/* begin time */
407c478bd9Sstevel@tonic-gate 	struct	timeval p_etime;	/* end time */
417c478bd9Sstevel@tonic-gate 	struct	rusage p_rusage;
427c478bd9Sstevel@tonic-gate  tchar *p_command;		/* first PMAXLEN chars of command */
437c478bd9Sstevel@tonic-gate };
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /* added for status */
467c478bd9Sstevel@tonic-gate #define	ABN_TERM	0200
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /* flag values for p_flags */
497c478bd9Sstevel@tonic-gate #define	PRUNNING	(1<<0)		/* running */
507c478bd9Sstevel@tonic-gate #define	PSTOPPED	(1<<1)		/* stopped */
517c478bd9Sstevel@tonic-gate #define	PNEXITED	(1<<2)		/* normally exited */
527c478bd9Sstevel@tonic-gate #define	PAEXITED	(1<<3)		/* abnormally exited */
537c478bd9Sstevel@tonic-gate #define	PSIGNALED	(1<<4)		/* terminated by a signal != SIGINT */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate #define	PALLSTATES	(PRUNNING|PSTOPPED|PNEXITED|PAEXITED|PSIGNALED|PINTERRUPTED)
567c478bd9Sstevel@tonic-gate #define	PNOTIFY		(1<<5)		/* notify async when done */
577c478bd9Sstevel@tonic-gate #define	PTIME		(1<<6)		/* job times should be printed */
587c478bd9Sstevel@tonic-gate #define	PAWAITED	(1<<7)		/* top level is waiting for it */
597c478bd9Sstevel@tonic-gate #define	PFOREGND	(1<<8)		/* started in shells pgrp */
607c478bd9Sstevel@tonic-gate #define	PDUMPED		(1<<9)		/* process dumped core */
617c478bd9Sstevel@tonic-gate #define	PDIAG		(1<<10)		/* diagnostic output also piped out */
627c478bd9Sstevel@tonic-gate #define	PPOU		(1<<11)		/* piped output */
637c478bd9Sstevel@tonic-gate #define	PREPORTED	(1<<12)		/* status has been reported */
647c478bd9Sstevel@tonic-gate #define	PINTERRUPTED	(1<<13)		/* job stopped via interrupt signal */
657c478bd9Sstevel@tonic-gate #define	PPTIME		(1<<14)		/* time individual process */
667c478bd9Sstevel@tonic-gate #define	PNEEDNOTE	(1<<15)		/* notify as soon as practical */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	PNULL		(struct process *)0
697c478bd9Sstevel@tonic-gate #define	PMAXLEN		80
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /* defines for arguments to pprint */
727c478bd9Sstevel@tonic-gate #define	NUMBER		01
737c478bd9Sstevel@tonic-gate #define	NAME		02
747c478bd9Sstevel@tonic-gate #define	REASON		04
757c478bd9Sstevel@tonic-gate #define	AMPERSAND	010
767c478bd9Sstevel@tonic-gate #define	FANCY		020
777c478bd9Sstevel@tonic-gate #define	SHELLDIR	040		/* print shell's dir if not the same */
787c478bd9Sstevel@tonic-gate #define	JOBDIR		0100		/* print job's dir if not the same */
797c478bd9Sstevel@tonic-gate #define	AREASON		0200
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate struct	process	proclist;		/* list head of all processes */
827c478bd9Sstevel@tonic-gate bool	pnoprocesses;			/* pchild found nothing to wait for */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate struct	process *pholdjob;		/* one level stack of current jobs */
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate struct	process *pcurrjob;		/* current job */
877c478bd9Sstevel@tonic-gate struct	process	*pcurrent;		/* current job in table */
887c478bd9Sstevel@tonic-gate struct	process *pprevious;		/* previous job in table */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate short	pmaxindex;			/* current maximum job index */
91