1 /* Yash: yet another shell */ 2 /* job.h: job control */ 3 /* (C) 2007-2017 magicant */ 4 5 /* This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 19 #ifndef YASH_JOB_H 20 #define YASH_JOB_H 21 22 #include <stddef.h> 23 #include <sys/types.h> 24 #include "xgetopt.h" 25 26 27 /* status of job/process */ 28 typedef enum jobstatus_T { 29 JS_RUNNING, JS_STOPPED, JS_DONE, 30 } jobstatus_T; 31 32 /* info about a process in a job */ 33 typedef struct process_T { 34 pid_t pr_pid; /* process ID */ 35 jobstatus_T pr_status; 36 int pr_statuscode; 37 wchar_t *pr_name; /* process name made from command line */ 38 } process_T; 39 /* If `pr_pid' is 0, the process was finished without `fork'ing from the shell. 40 * In this case, `pr_status' is JS_DONE and `pr_statuscode' is the exit status. 41 * If `pr_pid' is a positive number, it's the process ID. In this case, 42 * `pr_statuscode' is the status code returned by `waitpid'. */ 43 44 /* info about a job */ 45 typedef struct job_T { 46 pid_t j_pgid; /* process group ID */ 47 jobstatus_T j_status; 48 _Bool j_statuschanged; /* job's status not yet reported? */ 49 _Bool j_legacy; /* not a true child of the shell? */ 50 _Bool j_nonotify; /* suppress printing job status? */ 51 size_t j_pcount; /* # of processes in `j_procs' */ 52 process_T j_procs[]; /* info about processes */ 53 } job_T; 54 /* When job control is off, `j_pgid' is 0 since the job shares the process group 55 * ID with the shell. 56 * In subshells, the `j_legacy' flag is set to indicate that the job is not 57 * a direct child of the current shell process. */ 58 59 60 /* job number of the active job */ 61 #define ACTIVE_JOBNO 0 62 63 /* When a process is stopped/terminated by a signal, this value is added to the 64 * signal number to make the value of the exit status. 65 * 128 in bash/zsh/dash/pdksh/mksh/posh, 256 in ksh. */ 66 #ifndef TERMSIGOFFSET 67 #define TERMSIGOFFSET 384 68 #endif 69 70 extern void init_job(void); 71 72 extern void set_active_job(job_T *job) 73 __attribute__((nonnull)); 74 extern void add_job(_Bool current); 75 extern void remove_job(size_t jobnumber); 76 extern void remove_job_nofitying_signal(size_t jobnumber); 77 extern void remove_all_jobs(void); 78 extern void neglect_all_jobs(void); 79 extern size_t job_count(void) 80 __attribute__((pure)); 81 extern size_t stopped_job_count(void) 82 __attribute__((pure)); 83 84 extern void do_wait(void); 85 extern int wait_for_job(size_t jobnumber, _Bool return_on_stop, 86 _Bool interruptible, _Bool return_on_trap); 87 extern wchar_t **wait_for_child(pid_t cpid, pid_t cpgid, _Bool return_on_stop); 88 extern pid_t get_job_pgid(const wchar_t *jobname) 89 __attribute__((pure)); 90 91 extern void put_foreground(pid_t pgrp); 92 extern void ensure_foreground(void); 93 94 extern int calc_status_of_job(const job_T *job) 95 __attribute__((pure,nonnull)); 96 97 extern _Bool any_job_status_has_changed(void) 98 __attribute__((pure)); 99 extern void print_job_status_all(void); 100 extern void notify_signaled_job(size_t jobnumber); 101 102 extern int jobs_builtin(int argc, void **argv) 103 __attribute__((nonnull)); 104 #if YASH_ENABLE_HELP 105 extern const char jobs_help[], jobs_syntax[]; 106 #endif 107 extern const struct xgetopt_T jobs_options[]; 108 109 extern int fg_builtin(int argc, void **argv) 110 __attribute__((nonnull)); 111 #if YASH_ENABLE_HELP 112 extern const char fg_help[], fg_syntax[], bg_help[], bg_syntax[]; 113 #endif 114 115 extern int wait_builtin(int argc, void **argv) 116 __attribute__((nonnull)); 117 #if YASH_ENABLE_HELP 118 extern const char wait_help[], wait_syntax[]; 119 #endif 120 121 extern int disown_builtin(int argc, void **argv) 122 __attribute__((nonnull)); 123 #if YASH_ENABLE_HELP 124 extern const char disown_help[], disown_syntax[]; 125 #endif 126 127 128 #endif /* YASH_JOB_H */ 129 130 131 /* vim: set ts=8 sts=4 sw=4 noet tw=80: */ 132