-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
73 lines (69 loc) · 2.14 KB
/
main.c
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
64
65
66
67
68
69
70
71
72
73
#include "main.h"
#include <dirent.h>
#include <fcntl.h>
#include <readline/history.h>
#include <readline/readline.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <unistd.h>
#include "execute_command.h"
#include "init_shell.h"
#include "ls_implement.h"
#include "pinfo.h"
#include "signal_handling.h"
#include "wait_input.h"
#define clear() printf("\033[H\033[J")
// Global Variables
char home_dir[1024];
int background_pids[200];
int stopped_pids[200];
int no_of_backgroundprocess = 0;
char **background_process;
int main() {
clear();
background_process = (char **)malloc(2000 * sizeof(char **));
signal(SIGTSTP, sigintHandlerZ);
signal(SIGINT, sigintHandlerC);
getcwd(home_dir, sizeof(home_dir));
init_shell();
while (1) {
wait_input();
int pid, pid_status;
signal(SIGINT, sigintHandlerC);
// signal(SIGTSTP, sigintHandlerZ);
while ((pid = waitpid(-1, &pid_status, WNOHANG | WUNTRACED)) > 0) {
if (WIFEXITED(pid_status)) {
for (int i = 0; i < no_of_backgroundprocess; i++) {
if (background_pids[i] == pid) {
background_pids[i] = 0;
printf(
"Background process (%s) of 'PID' : %d exited "
"successfully \n",
background_process[i], pid);
break;
}
}
} else if (WIFSIGNALED(pid_status)) {
for (int i = 0; i < no_of_backgroundprocess; i++) {
if (background_pids[i] == pid) {
background_pids[i] = 0;
printf(
"Background process (%s) of 'PID' : %d exited "
"successfully \n",
background_process[i], pid);
break;
}
}
}
}
init_shell();
}
return 0;
}