-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.h
More file actions
52 lines (39 loc) · 1.35 KB
/
Copy pathshell.h
File metadata and controls
52 lines (39 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef SHELL_H
#define SHELL_H
#define _GNU_SOURCE
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/wait.h"
#include "signal.h"
#include "fcntl.h"
#define MAX_CMD_BUFFER 255
extern volatile sig_atomic_t pid_foreground;
//volatile to avoid unexpected changes from a handler
//sig_atomic_t is a type of integer that can be safely read/written in a signal handler
//called pid_foreground because it is meant to track the ID of the child process currently running in the foreground.
typedef enum {RUNNING, STOPPED, DONE} job_status;
typedef struct job {
pid_t pid;
int id;
char *line;
job_status status;
struct job *next;
} job;
extern int latest_exit_status; //tracks latest command's exit status to support echo $? (part of Milestone 4)
extern job *job_list;
void sigint_handler(int signal);
void sigtstp_handler(int signal);
void sigchld_handler(int signal);
job *add_job(pid_t pid, const char *line, job_status status);
void remove_job(job *j);
job* find_job(int id);
void update_job_status(pid_t pid, job_status status);
void notify_job(job *j, const char *status_line);
void list_jobs();
void parse_command(char *line, char **args, char **input_file, char **output_file, int *bgCheck);
void apply_redirection(char *input_file, char *output_file);
void restore_redirection();
#endif