1 | #include <signal.h> |
---|---|
2 | #include <stdio.h> |
3 | #include <vector> |
4 | |
5 | static int signal_counter = 0; |
6 | |
7 | static void count_signal(int signo) { |
8 | ++signal_counter; |
9 | printf(format: "Signal %d\n", signo); |
10 | } |
11 | |
12 | static void raise_signals() { |
13 | std::vector<int> signals( |
14 | {SIGSEGV, SIGUSR1, SIGUSR2, SIGALRM, SIGFPE, SIGBUS, SIGINT, SIGHUP}); |
15 | |
16 | for (int signal_num : signals) { |
17 | signal(sig: signal_num, handler: count_signal); |
18 | } |
19 | |
20 | for (int signal_num : signals) { |
21 | raise(sig: signal_num); |
22 | } |
23 | } |
24 | |
25 | int main() { |
26 | raise_signals(); |
27 | return signal_counter; |
28 | } |
29 |