-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsig.c
40 lines (37 loc) · 1.17 KB
/
sig.c
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
/* sig.c
*
* Copyright (C) 2018 < Daniel Finneran, [email protected] >
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the GPL license. See the LICENSE file for details.
*/
#include<stdio.h>
#include<signal.h>
#include<unistd.h>
void sig_handler(int signo)
{
if (signo == SIGUSR1)
printf("received SIGUSR1\n");
else if (signo == SIGKILL)
printf("received SIGKILL\n");
else if (signo == SIGSTOP)
printf("received SIGSTOP\n");
else if (signo == SIGTERM)
printf("received SIGTERM\n");
else if (signo == SIGINT)
printf("received SIGINT\n");
}
void setSignalHander() {
printf("Setting up Signal handlers to capture kill signals\n");
if (signal(SIGUSR1, sig_handler) == SIG_ERR)
printf("can't catch SIGUSR1\n");
if (signal(SIGKILL, sig_handler) == SIG_ERR)
printf("can't catch SIGKILL\n");
if (signal(SIGSTOP, sig_handler) == SIG_ERR)
printf("can't catch SIGSTOP\n");
if (signal(SIGTERM, sig_handler) == SIG_ERR)
printf("can't catch SIGTERM\n");
if (signal(SIGINT, sig_handler) == SIG_ERR)
printf("can't catch SIGINT\n");
}