catch ctrl c
This commit is contained in:
parent
236db39240
commit
0f51870e63
37
bish.cc
37
bish.cc
|
@ -21,9 +21,7 @@ using namespace std;
|
|||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
struct sigaction act;
|
||||
act.sa_handler = ctrlCHandler;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
signal(SIGINT, ctrlCHandler);
|
||||
|
||||
stringstream prompt;
|
||||
static char* line = (char*)NULL;
|
||||
|
@ -134,22 +132,23 @@ int main(int argc, char **argv){
|
|||
|
||||
int status;
|
||||
|
||||
if (!cmd->background)
|
||||
do {
|
||||
if (waitpid(kidpid, &status, WUNTRACED | WCONTINUED) == -1) {
|
||||
perror("waitpid");
|
||||
exit(1);
|
||||
}
|
||||
if (WIFEXITED(status)) {
|
||||
cout << "(" << WEXITSTATUS(status) << "):";
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
cout << endl << "killed by signal " << WTERMSIG(status) << endl;
|
||||
} else if (WIFSTOPPED(status)) {
|
||||
cout << endl << "stopped by signal " << WSTOPSIG(status) << endl;
|
||||
} else if (WIFCONTINUED(status)) {
|
||||
cout << endl << "continued" << endl;
|
||||
}
|
||||
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
||||
if (!cmd->background){
|
||||
do {
|
||||
if (waitpid(kidpid, &status, WUNTRACED | WCONTINUED) == -1) {
|
||||
perror("waitpid");
|
||||
exit(1);
|
||||
}
|
||||
if (WIFEXITED(status)) {
|
||||
cout << "(" << WEXITSTATUS(status) << "):";
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
cout << endl << "killed by signal " << WTERMSIG(status) << endl;
|
||||
} else if (WIFSTOPPED(status)) {
|
||||
cout << endl << "stopped by signal " << WSTOPSIG(status) << endl;
|
||||
} else if (WIFCONTINUED(status)) {
|
||||
cout << endl << "continued" << endl;
|
||||
}
|
||||
} while (!WIFEXITED(status) && !WIFSIGNALED(status));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,19 @@
|
|||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
// #include "util_fns.h"
|
||||
using namespace std;
|
||||
|
||||
|
||||
void ctrlCHandler(int sig) {
|
||||
|
||||
if (sig == SIGINT) {
|
||||
// cout << "SIGINT received" << endl;
|
||||
// return;
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
// util methods
|
||||
|
|
Loading…
Reference in New Issue