-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <sys/signalfd.h> | ||
#include <signal.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
bool keep_running = true; | ||
|
||
void sig_handler(int signo) { | ||
cout << "Received signal " << signo << endl; | ||
if (signo == SIGABRT) { | ||
keep_running = false; | ||
} | ||
} | ||
|
||
int main(int argc, char* argv[]) { | ||
int type; | ||
cout << "Enter 1 for busy wait and anything else for blocking wait:" << endl; | ||
cin >> type; | ||
signal(SIGUSR1, sig_handler); | ||
signal(SIGUSR2, sig_handler); | ||
signal(SIGABRT, sig_handler); | ||
cout << "My pid is: " << getpid() << endl; | ||
if(type == 1) { | ||
while (keep_running); | ||
} else { | ||
while(keep_running) | ||
pause(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <sys/signalfd.h> | ||
#include <signal.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <iostream> | ||
#include <errno.h> | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]){ | ||
int pid, signal; | ||
cout << "Enter pid and signal" << endl; | ||
cin >> pid >> signal; | ||
if(kill(pid,signal) == -1){ | ||
if(errno==ESRCH){ | ||
cout << "PID inexistente" << endl; | ||
} | ||
else { | ||
cout << "Ocorreu um erro" << endl; | ||
} | ||
return 1; | ||
} | ||
return 0; | ||
} |