forked from TalMalchi/SIgnals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.cpp
89 lines (75 loc) · 1.35 KB
/
signals.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
using namespace std;
void handler(int signum)
{
int x = 6;
int y = 0;
int z;
switch (signum)
{
case SIGCHLD:
cout << "received SIGCHLD\n"
<< endl;
fflush(stdout);
z = x / y;
case SIGFPE:
cout << "received SIGFPE\n"
<< endl;
fflush(stdout);
abort();
cout << "Press ^C\n"
<< endl;
sleep(10);
cout << "\n" <<endl;
case SIGABRT:
cout << "received SIGABRT\n"
<< endl;
fflush(stdout);
alarm(3);
case SIGALRM:
cout << "received SIGALRM\n"
<< endl;
fflush(stdout);
raise(SIGUSR1);
case SIGUSR1:
cout << "received SIGUSR1\n" <<endl;
fflush(stdout);
//system("lsd"); //instead ls
cout << "\n"<< endl;
exit(1);
// // case SIGILL:
// // cout << "received SIGILL\n" <<endl;
// // fflush(stdout);
// // //exit(1);
// // system("^C");
// case SIGTERM:
// cout << "received SIGTERM\n" <<endl;
// fflush(stdout);
// exit(1);
default :
exit(1);
}}
int main()
{
int status;
signal(SIGCHLD, handler);
signal(SIGFPE, handler);
signal(SIGABRT, handler);
signal(SIGALRM, handler);
signal(SIGUSR1, handler);
// signal(SIGILL, handler);
// signal(SIGTERM, handler);
if (!(fork()))
{
exit(1);
}
wait(&status);
return 0;
}