-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
47 lines (40 loc) · 1.18 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
///////////// HW2 - OS /////////////
///// Yosi Kariv - 205507460 /////
///// Eldar Abramobich - 316462795 ///
////////////////////////////////////
#include "shell.h"
#include "shell.c"
int main(int argc, char **argv) {
int childPid;
char *cmdLine;
parseInfo *info;
printf("\033[0;36m################# Running custom shell ####################\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\033[0m\n");
while(1) {
printCurrentPath();
cmdLine = readline(" >> ");
info = parse(cmdLine);
if (strcmp(info->command, "exit") == 0) {
free(cmdLine);
free(info);
break;
}
if(!isPipe(info->arguments) && ifcd(info))
continue;
childPid = fork();
if (childPid == 0) {
// child code
executeCommand(info); // calls
exit(0);
} else if (childPid > 0) {
//parent code
waitpid(childPid, NULL, 0);
} else {
perror("fork");
}
// Free cmdLine and parseInfo resources
free(cmdLine);
free(info);
}
return 0;
}