#pragma prototyped
#ifndef JOB_NFLAG
#define JOBTTY 2
#include <ast.h>
#include <sfio.h>
#ifndef SIGINT
# include <signal.h>
#endif
#include "FEATURE/options"
#undef JOBS
#if defined(SIGCLD) && !defined(SIGCHLD)
# define SIGCHLD SIGCLD
#endif
#ifdef SIGCHLD
# define JOBS 1
# include "terminal.h"
# ifdef FIOLOOKLD
extern int tty_ld, ntty_ld;
# define OTTYDISC tty_ld
# define NTTYDISC ntty_ld
# endif
#else
# undef SIGTSTP
# undef SH_MONITOR
# define SH_MONITOR 0
# define job_set(x)
# define job_reset(x)
#endif
struct process
{
struct process *p_nxtjob;
struct process *p_nxtproc;
pid_t p_pid;
pid_t p_pgrp;
pid_t p_fgrp;
short p_job;
unsigned short p_exit;
unsigned short p_exitmin;
unsigned short p_flag;
int p_env;
#ifdef JOBS
off_t p_name;
struct termios p_stty;
#endif
};
struct jobs
{
struct process *pwlist;
pid_t curpgid;
pid_t parent;
pid_t mypid;
pid_t mypgid;
pid_t mytgid;
unsigned int in_critical;
int savesig;
int numpost;
short fd;
#ifdef JOBS
int suspend;
int linedisc;
#endif
char jobcontrol;
char waitsafe;
char waitall;
char toclear;
unsigned char *freejobs;
};
#define JOB_LFLAG 1
#define JOB_NFLAG 2
#define JOB_PFLAG 4
#define JOB_NLFLAG 8
extern struct jobs job;
#ifdef JOBS
#if !_std_malloc
#include <vmalloc.h>
#if VMALLOC_VERSION >= 20070911L
#define vmbusy() (vmstat(0,0)!=0)
#endif
#endif
#ifndef vmbusy
#define vmbusy() 0
#endif
#define job_lock() (job.in_critical++)
#define job_unlock() do{if(!--job.in_critical&&job.savesig&&!vmbusy())job_reap(job.savesig);}while(0)
extern const char e_jobusage[];
extern const char e_done[];
extern const char e_running[];
extern const char e_coredump[];
extern const char e_no_proc[];
extern const char e_no_job[];
extern const char e_jobsrunning[];
extern const char e_nlspace[];
extern const char e_access[];
extern const char e_terminate[];
extern const char e_no_jctl[];
extern const char e_signo[];
#ifdef SIGTSTP
extern const char e_no_start[];
#endif
#ifdef NTTYDISC
extern const char e_newtty[];
extern const char e_oldtty[];
#endif
#endif
extern void job_clear(void);
extern void job_bwait(char**);
extern int job_walk(Sfio_t*,int(*)(struct process*,int),int,char*[]);
extern int job_kill(struct process*,int);
extern void job_wait(pid_t);
extern int job_post(pid_t,pid_t);
extern void *job_subsave(void);
extern void job_subrestore(void*);
#ifdef JOBS
extern void job_init(int);
extern int job_close(void);
extern int job_list(struct process*,int);
extern int job_terminate(struct process*,int);
extern int job_switch(struct process*,int);
extern void job_fork(pid_t);
extern int job_reap(int);
#else
# define job_init(flag)
# define job_close() (0)
# define job_fork(p)
#endif
#endif