-
Notifications
You must be signed in to change notification settings - Fork 2
/
process.h
63 lines (52 loc) · 1.32 KB
/
process.h
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
53
54
55
56
57
58
59
60
61
62
63
#ifndef PROCESS_H
#define PROCESS_H
#include <fcntl.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include "data.h"
#define READ 0
#define WRITE 1
#define JOBS_CAPACITY 1024
// for CTRL-C interruption
extern sigjmp_buf env;
extern volatile sig_atomic_t jump_active;
// for background jobs
typedef struct job {
size_t bg_cnt;
size_t job_cnt;
size_t table_size;
size_t* stat_table;
pid_t** pid_table;
char** cmd_table;
} job_t;
job_t job;
pid_t pgid; // store child process group pid for grouping
char OLDPWD[BUFFER_SIZE]; // store last working directory for cmd "cd -"
int pipe_fd[PROCESS_SIZE][2]; // store pipe file descriptor for piping
// called in mumsh.c
void sigint_handler();
void reap_background_jobs();
void mumsh_exec_cmds();
void free_jobs();
int mumsh_cmd_cd();
int mumsh_cmd_exit();
// called in process.c
int add_bytes();
void init_jobs_table();
void print_formatted_cmds();
void exec_cmd(token_t* token);
void mumsh_cmd_pwd(token_t* token);
void mumsh_cmd_jobs(token_t* token);
void input_redirect();
void output_redirect();
// exit process
void exit_process(int exit_code, char* content);
// for debug
void debug_process(pid_t pid, int status);
void debug_jobs();
#endif // PROCESS_H