]> git.ipfire.org Git - thirdparty/bash.git/blame - jobs.h
Imported from ../bash-2.05a.tar.gz.
[thirdparty/bash.git] / jobs.h
CommitLineData
726f6388
JA
1/* jobs.h -- structures and stuff used by the jobs.c file. */
2
3/* Copyright (C) 1993 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
bb70624e 19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
726f6388 20
ccc6cda3
JA
21#if !defined (_JOBS_H_)
22# define _JOBS_H_
726f6388
JA
23
24#include "quit.h"
25#include "siglist.h"
26
27#include "stdc.h"
28
d166f048
JA
29#include "posixwait.h"
30
726f6388 31/* Defines controlling the fashion in which jobs are listed. */
ccc6cda3
JA
32#define JLIST_STANDARD 0
33#define JLIST_LONG 1
34#define JLIST_PID_ONLY 2
35#define JLIST_CHANGED_ONLY 3
36#define JLIST_NONINTERACTIVE 4
37
726f6388
JA
38/* I looked it up. For pretty_print_job (). The real answer is 24. */
39#define LONGEST_SIGNAL_DESC 24
40
41/* We keep an array of jobs. Each entry in the array is a linked list
42 of processes that are piped together. The first process encountered is
43 the group leader. */
44
f73dda09
JA
45/* Values for the `running' field of a struct process. */
46#define PS_DONE 0
47#define PS_RUNNING 1
48#define PS_STOPPED 2
49
726f6388
JA
50/* Each child of the shell is remembered in a STRUCT PROCESS. A chain of
51 such structures is a pipeline. The chain is circular. */
52typedef struct process {
53 struct process *next; /* Next process in the pipeline. A circular chain. */
54 pid_t pid; /* Process ID. */
55 WAIT status; /* The status of this command as returned by wait. */
56 int running; /* Non-zero if this process is running. */
57 char *command; /* The particular program that is running. */
58} PROCESS;
59
60/* A description of a pipeline's state. */
61typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
62#define JOBSTATE(job) (jobs[(job)]->state)
63
ccc6cda3
JA
64#define STOPPED(j) (jobs[(j)]->state == JSTOPPED)
65#define RUNNING(j) (jobs[(j)]->state == JRUNNING)
66#define DEADJOB(j) (jobs[(j)]->state == JDEAD)
67
726f6388
JA
68/* Values for the FLAGS field in the JOB struct below. */
69#define J_FOREGROUND 0x01 /* Non-zero if this is running in the foreground. */
70#define J_NOTIFIED 0x02 /* Non-zero if already notified about job state. */
71#define J_JOBCONTROL 0x04 /* Non-zero if this job started under job control. */
ccc6cda3
JA
72#define J_NOHUP 0x08 /* Don't send SIGHUP to job if shell gets SIGHUP. */
73
74#define IS_FOREGROUND(j) ((jobs[j]->flags & J_FOREGROUND) != 0)
75#define IS_NOTIFIED(j) ((jobs[j]->flags & J_NOTIFIED) != 0)
76#define IS_JOBCONTROL(j) ((jobs[j]->flags & J_JOBCONTROL) != 0)
726f6388
JA
77
78typedef struct job {
79 char *wd; /* The working directory at time of invocation. */
80 PROCESS *pipe; /* The pipeline of processes that make up this job. */
81 pid_t pgrp; /* The process ID of the process group (necessary). */
82 JOB_STATE state; /* The state that this job is in. */
83 int flags; /* Flags word: J_NOTIFIED, J_FOREGROUND, or J_JOBCONTROL. */
84#if defined (JOB_CONTROL)
85 COMMAND *deferred; /* Commands that will execute when this job is done. */
f73dda09 86 sh_vptrfunc_t *j_cleanup; /* Cleanup function to call when job marked JDEAD */
ccc6cda3 87 PTR_T cleanarg; /* Argument passed to (*j_cleanup)() */
726f6388
JA
88#endif /* JOB_CONTROL */
89} JOB;
90
91#define NO_JOB -1 /* An impossible job array index. */
92#define DUP_JOB -2 /* A possible return value for get_job_spec (). */
93
94/* A value which cannot be a process ID. */
95#define NO_PID (pid_t)-1
96
726f6388 97/* System calls. */
ccc6cda3 98#if !defined (HAVE_UNISTD_H)
726f6388 99extern pid_t fork (), getpid (), getpgrp ();
ccc6cda3 100#endif /* !HAVE_UNISTD_H */
726f6388
JA
101
102/* Stuff from the jobs.c file. */
bb70624e 103extern pid_t original_pgrp, shell_pgrp, pipeline_pgrp;
726f6388
JA
104extern pid_t last_made_pid, last_asynchronous_pid;
105extern int current_job, previous_job;
106extern int asynchronous_notification;
107extern JOB **jobs;
108extern int job_slots;
109
110extern void making_children __P((void));
111extern void stop_making_children __P((void));
112extern void cleanup_the_pipeline __P((void));
ccc6cda3
JA
113extern void save_pipeline __P((int));
114extern void restore_pipeline __P((int));
726f6388
JA
115extern void start_pipeline __P((void));
116extern int stop_pipeline __P((int, COMMAND *));
d166f048 117
cce855bc 118extern void delete_job __P((int, int));
ccc6cda3 119extern void nohup_job __P((int));
cce855bc
JA
120extern void delete_all_jobs __P((int));
121extern void nohup_all_jobs __P((int));
726f6388 122
bb70624e
JA
123extern int count_all_jobs __P((void));
124
726f6388
JA
125extern void terminate_current_pipeline __P((void));
126extern void terminate_stopped_jobs __P((void));
127extern void hangup_all_jobs __P((void));
128extern void kill_current_pipeline __P((void));
129
130#if defined (__STDC__) && defined (pid_t)
d166f048 131extern int get_job_by_pid __P((int, int));
726f6388
JA
132extern void describe_pid __P((int));
133#else
d166f048 134extern int get_job_by_pid __P((pid_t, int));
726f6388
JA
135extern void describe_pid __P((pid_t));
136#endif
137
ccc6cda3
JA
138extern void list_one_job __P((JOB *, int, int, int));
139extern void list_all_jobs __P((int));
140extern void list_stopped_jobs __P((int));
141extern void list_running_jobs __P((int));
726f6388
JA
142
143extern pid_t make_child __P((char *, int));
bb70624e 144
726f6388
JA
145extern int get_tty_state __P((void));
146extern int set_tty_state __P((void));
147
148extern int wait_for_single_pid __P((pid_t));
149extern void wait_for_background_pids __P((void));
150extern int wait_for __P((pid_t));
151extern int wait_for_job __P((int));
152
153extern void notify_and_cleanup __P((void));
154extern void reap_dead_jobs __P((void));
155extern int start_job __P((int, int));
156extern int kill_pid __P((pid_t, int, int));
d166f048 157extern int initialize_job_control __P((int));
726f6388 158extern void initialize_job_signals __P((void));
28ef6c31 159extern int give_terminal_to __P((pid_t, int));
726f6388 160
ccc6cda3
JA
161extern void set_sigwinch_handler __P((void));
162extern void unset_sigwinch_handler __P((void));
163
164extern void unfreeze_jobs_list __P((void));
726f6388
JA
165extern int set_job_control __P((int));
166extern void without_job_control __P((void));
167extern void end_job_control __P((void));
168extern void restart_job_control __P((void));
169extern void set_sigchld_handler __P((void));
ccc6cda3
JA
170extern void ignore_tty_job_signals __P((void));
171extern void default_tty_job_signals __P((void));
726f6388
JA
172
173#if defined (JOB_CONTROL)
174extern int job_control;
175#endif
176
ccc6cda3 177#endif /* _JOBS_H_ */