-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathshell.cc
More file actions
65 lines (57 loc) · 1.15 KB
/
shell.cc
File metadata and controls
65 lines (57 loc) · 1.15 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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "command.hh"
#include "signal.h"
#include "stdlib.h"
#include "stdio.h"
#include <sys/types.h>
#include <sys/wait.h>
extern char * history [];
void yyrestart(FILE * file);
int yyparse(void);
extern "C" void ctrlC (int sig) {
printf("\nctrl c works\n");
Command::_currentCommand.prompt();
}
extern "C" void zombie(int sig) {
int pid = wait3(0, 0, NULL);
while (waitpid(-1, NULL, WNOHANG) > 0);
}
int main() {
struct sigaction sigA1;
sigA1.sa_handler = ctrlC;
sigemptyset(&sigA1.sa_mask);
sigA1.sa_flags = SA_RESTART;
int error = sigaction(SIGINT, &sigA1, NULL);
if(error){
perror("sigaction");
exit(-1);
}
//Zombie Process
struct sigaction sigA2;
sigA2.sa_handler = zombie;
sigemptyset(&sigA2.sa_mask);
sigA2.sa_flags = SA_RESTART;
error = sigaction(SIGCHLD, &sigA2, NULL);
if (error) {
perror("sigaction");
exit(-1);
}
FILE* fd = fopen(".shellrc", "r");
if (fd) {
yyrestart(fd);
yyparse();
yyrestart(stdin);
fclose(fd);
}
else{
Command::_currentCommand.prompt();
}
//Command::_currentCommand.prompt();
yyparse();
/*
for(int i = 0; i < 1024; i++){
if(history[i] != NULL){
free(history[i]);
}
}
*/
}