aboutsummaryrefslogtreecommitdiff
path: root/lab5_shelllab/jobs.h
diff options
context:
space:
mode:
Diffstat (limited to 'lab5_shelllab/jobs.h')
-rw-r--r--lab5_shelllab/jobs.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/lab5_shelllab/jobs.h b/lab5_shelllab/jobs.h
new file mode 100644
index 0000000..0e69d87
--- /dev/null
+++ b/lab5_shelllab/jobs.h
@@ -0,0 +1,45 @@
+//-*-c++-*-
+#ifndef _jobs_h_
+#define _jobs_h_
+
+#include <sys/types.h> // needed for pid_t
+#include "globals.h"
+
+/* Job states */
+#define UNDEF 0 /* undefined */
+#define FG 1 /* running in foreground */
+#define BG 2 /* running in background */
+#define ST 3 /* stopped */
+
+/*
+ * Jobs states: FG (foreground), BG (background), ST (stopped)
+ * Job state transitions and enabling actions:
+ * FG -> ST : ctrl-z
+ * ST -> FG : fg command
+ * ST -> BG : bg command
+ * BG -> FG : fg command
+ * At most 1 job can be in the FG state.
+ */
+
+struct job_t { /* The job struct */
+ pid_t pid; /* job PID */
+ int jid; /* job ID [1, 2, ...] */
+ int state; /* UNDEF, BG, FG, or ST */
+ char cmdline[MAXLINE]; /* command line */
+};
+extern struct job_t jobs[MAXJOBS]; /* The job list */
+
+
+void clearjob(struct job_t *job);
+void initjobs(struct job_t *jobs);
+int maxjid(struct job_t *jobs);
+int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline);
+int deletejob(struct job_t *jobs, pid_t pid);
+pid_t fgpid(struct job_t *jobs);
+struct job_t *getjobpid(struct job_t *jobs, pid_t pid);
+struct job_t *getjobjid(struct job_t *jobs, int jid);
+int pid2jid(pid_t pid);
+void listjobs(struct job_t *jobs);
+
+
+#endif