-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmash.cpp
More file actions
34 lines (31 loc) · 967 Bytes
/
smash.cpp
File metadata and controls
34 lines (31 loc) · 967 Bytes
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
#include <iostream>
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include "Commands.h"
#include "signals.h"
int main(int argc, char* argv[]) {
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 sa;
sa.sa_handler = alarmHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if(sigaction(SIGALRM , &sa, NULL) == -1) {
perror("smash error: failed to set alarm handler");
}
alarm(0);
SmallShell& smash = SmallShell::getInstance();
while(true){
std::cout << smash.getName() + "> ";
std::string cmd_line;
std::getline(std::cin, cmd_line);
smash.executeCommand(cmd_line.c_str());
smash.jobs.removeFinishedJobs();
}
return 0;
}