1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1982-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * David Korn <dgk@research.att.com> *
19 ***********************************************************************/
23 * Interface to job control for shell
24 * written by David Korn
35 #include "FEATURE/options"
38 #if defined(SIGCLD) && !defined(SIGCHLD)
39 # define SIGCHLD SIGCLD
43 # include "terminal.h"
46 extern int tty_ld
, ntty_ld
;
47 # define OTTYDISC tty_ld
48 # define NTTYDISC ntty_ld
49 # endif /* FIOLOOKLD */
60 struct process
*p_nxtjob
; /* next job structure */
61 struct process
*p_nxtproc
; /* next process in current job */
62 pid_t p_pid
; /* process id */
63 pid_t p_pgrp
; /* process group */
64 pid_t p_fgrp
; /* process group when stopped */
65 short p_job
; /* job number of process */
66 unsigned short p_exit
; /* exit value or signal number */
67 unsigned short p_exitmin
; /* minimum exit value for xargs */
68 unsigned short p_flag
; /* flags - see below */
69 int p_env
; /* subshell environment number */
71 off_t p_name
; /* history file offset for command */
72 struct termios p_stty
; /* terminal state for job */
78 struct process
*pwlist
; /* head of process list */
79 pid_t curpgid
; /* current process gid id */
80 pid_t parent
; /* set by fork() */
81 pid_t mypid
; /* process id of shell */
82 pid_t mypgid
; /* process group id of shell */
83 pid_t mytgid
; /* terminal group id of shell */
84 unsigned int in_critical
; /* >0 => in critical region */
85 int savesig
; /* active signal */
86 int numpost
; /* number of posted jobs */
88 int numbjob
; /* number of background jobs */
89 #endif /* SHOPT_BGX */
90 short fd
; /* tty descriptor number */
92 int suspend
; /* suspend character */
93 int linedisc
; /* line dicipline */
95 char jobcontrol
; /* turned on for real job control */
96 char waitsafe
; /* wait will not block */
97 char waitall
; /* wait for all jobs in pipe */
98 char toclear
; /* job table needs clearing */
99 unsigned char *freejobs
; /* free jobs numbers */
102 /* flags for joblist */
108 extern struct jobs job
;
114 #if VMALLOC_VERSION >= 20070911L
115 #define vmbusy() (vmstat(0,0)!=0)
122 #define job_lock() (job.in_critical++)
123 #define job_unlock() \
126 if (!--job.in_critical && (sig = job.savesig)) \
128 if (!job.in_critical++ && !vmbusy()) \
134 extern const char e_jobusage
[];
135 extern const char e_done
[];
136 extern const char e_running
[];
137 extern const char e_coredump
[];
138 extern const char e_no_proc
[];
139 extern const char e_no_job
[];
140 extern const char e_jobsrunning
[];
141 extern const char e_nlspace
[];
142 extern const char e_access
[];
143 extern const char e_terminate
[];
144 extern const char e_no_jctl
[];
145 extern const char e_signo
[];
147 extern const char e_no_start
[];
150 extern const char e_newtty
[];
151 extern const char e_oldtty
[];
152 #endif /* NTTYDISC */
156 * The following are defined in jobs.c
159 extern void job_clear(void);
160 extern void job_bwait(char**);
161 extern int job_walk(Sfio_t
*,int(*)(struct process
*,int),int,char*[]);
162 extern int job_kill(struct process
*,int);
163 extern int job_wait(pid_t
);
164 extern int job_post(pid_t
,pid_t
);
165 extern void *job_subsave(void);
166 extern void job_subrestore(void*);
168 extern void job_chldtrap(Shell_t
*, const char*,int);
169 #endif /* SHOPT_BGX */
171 extern void job_init(Shell_t
*,int);
172 extern int job_close(Shell_t
*);
173 extern int job_list(struct process
*,int);
174 extern int job_terminate(struct process
*,int);
175 extern int job_switch(struct process
*,int);
176 extern void job_fork(pid_t
);
177 extern int job_reap(int);
179 # define job_init(s,flag)
180 # define job_close(s) (0)
185 #endif /* !JOB_NFLAG */