-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmash.cpp
35 lines (29 loc) · 931 Bytes
/
smash.cpp
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
#include "Commands.h"
#include "signals.h"
// definition of global variables
pid_t SMASH_PROCESS_PID = 0;
bool QUIT_SHELL = false;
int main(int argc, char* argv[]) {
SMASH_PROCESS_PID = getpid();
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");
}
struct sigaction act;
act.sa_handler = alarmHandler;
sigemptyset (&act.sa_mask);
act.sa_flags = SA_RESTART;
if(sigaction(SIGALRM , &act ,nullptr) < 0) {
perror("smash error: sigaction failed");
}
SmallShell& smash = SmallShell::getInstance();
while(!QUIT_SHELL) {
std::cout << smash.getPrompt() + "> ";
std::string cmd_line;
std::getline(std::cin, cmd_line);
smash.executeCommand(cmd_line.c_str());
}
return 0;
}