jobs.h revision 28346
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Kenneth Almquist. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 3. All advertising materials mentioning features or use of this software 171556Srgrimes * must display the following acknowledgement: 181556Srgrimes * This product includes software developed by the University of 191556Srgrimes * California, Berkeley and its contributors. 201556Srgrimes * 4. Neither the name of the University nor the names of its contributors 211556Srgrimes * may be used to endorse or promote products derived from this software 221556Srgrimes * without specific prior written permission. 231556Srgrimes * 241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3436150Scharnier * SUCH DAMAGE. 3536150Scharnier * 3636150Scharnier * @(#)jobs.h 8.2 (Berkeley) 5/4/95 371556Srgrimes * $Id: jobs.h,v 1.5 1997/02/22 13:58:29 peter Exp $ 3899110Sobrien */ 3999110Sobrien 401556Srgrimes/* Mode argument to forkshell. Don't change FORK_FG or FORK_BG. */ 4117987Speter#define FORK_FG 0 4217987Speter#define FORK_BG 1 4317987Speter#define FORK_NOJOB 2 4417987Speter 4517987Speter 4617987Speter/* 4717987Speter * A job structure contains information about a job. A job is either a 481556Srgrimes * single process or a set of processes contained in a pipeline. In the 491556Srgrimes * latter case, pidlist will be non-NULL, and will point to a -1 terminated 501556Srgrimes * array of pids. 511556Srgrimes */ 521556Srgrimes 5317987Speterstruct procstat { 541556Srgrimes pid_t pid; /* process id */ 551556Srgrimes int status; /* status flags (defined above) */ 561556Srgrimes char *cmd; /* text of command being run */ 571556Srgrimes}; 581556Srgrimes 591556Srgrimes 601556Srgrimes/* states */ 611556Srgrimes#define JOBSTOPPED 1 /* all procs are stopped */ 621556Srgrimes#define JOBDONE 2 /* all procs are completed */ 63100588Stjr 641556Srgrimes 651556Srgrimesstruct job { 661556Srgrimes struct procstat ps0; /* status of process */ 671556Srgrimes struct procstat *ps; /* status or processes when more than one */ 681556Srgrimes short nprocs; /* number of processes */ 691556Srgrimes short pgrp; /* process group of this job */ 701556Srgrimes char state; /* true if job is finished */ 711556Srgrimes char used; /* true if this entry is in used */ 7212043Speter char changed; /* true if status has changed */ 731556Srgrimes#if JOBS 741556Srgrimes char jobctl; /* job running under job control */ 751556Srgrimes#endif 761556Srgrimes}; 771556Srgrimes 781556Srgrimesextern pid_t backgndpid; /* pid of last background process */ 791556Srgrimesextern int job_warning; /* user was warned about stopped jobs */ 801556Srgrimes 811556Srgrimesvoid setjobctl __P((int)); 821556Srgrimesint fgcmd __P((int, char **)); 831556Srgrimesint bgcmd __P((int, char **)); 841556Srgrimesint jobscmd __P((int, char **)); 851556Srgrimesvoid showjobs __P((int)); 8620425Ssteveint waitcmd __P((int, char **)); 8720425Ssteveint jobidcmd __P((int, char **)); 881556Srgrimesstruct job *makejob __P((union node *, int)); 891556Srgrimesint forkshell __P((struct job *, union node *, int)); 901556Srgrimesint waitforjob __P((struct job *)); 911556Srgrimesint stoppedjobs __P((void)); 921556Srgrimeschar *commandtext __P((union node *)); 931556Srgrimes 941556Srgrimes#if ! JOBS 951556Srgrimes#define setjobctl(on) /* do nothing */ 96201053Sjilles#endif 9712043Speter