-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmash.cpp
More file actions
39 lines (36 loc) · 1.08 KB
/
Copy pathsmash.cpp
File metadata and controls
39 lines (36 loc) · 1.08 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
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include "Commands.h"
#include "signals.h"
int main(int argc, char* argv[]) {
struct sigaction sa;
sa.sa_handler = alarmHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if(signal(SIGTSTP , ctrlZHandler)==SIG_ERR) {
perror("smash error: failed to set ctrl-Z handler");
}
if(signal(SIGINT , ctrlCHandler)==SIG_ERR) {
perror("smash error: failed to set ctrl-C handler");
}
if(sigaction(SIGALRM,&sa,nullptr) ==-1) {
perror("smash error: failed to set alarm handler");
}
SmallShell& smash = SmallShell::getInstance();
if(smash.getPID() == -1){
perror("smash error: getpid failed");
return 0;
}
while(true) {
std::cout << smash.getName()<<"> ";
std::string cmd_line;
std::getline(std::cin, cmd_line);
smash.executeCommand(cmd_line.c_str());
if(smash.isFinished() || smash.child()){
break;
}
}
return 0;
}