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
|
#include <signal.h>
#include <stdio.h>
#include <errno.h>
// Prints the state of the signal handlers to stdout
int main()
{
int open = 0, i;
sigset_t blockedsigs;
printf("ChildInfo { masked = [");
sigprocmask(SIG_BLOCK, NULL, &blockedsigs);
for(i = 0; i < NSIG; ++i)
{
int ret = sigismember(&blockedsigs, i);
if(ret >= 0)
{
if(!open)
open=1;
else
printf(",");
printf("(%d,%s)", i, ret == 1 ? "True" : "False");
}
}
printf("], handlers = [");
open = 0;
for(i = 0; i < NSIG; ++i)
{
struct sigaction old;
if(sigaction(i, NULL, &old) >= 0)
{
if(!open)
open=1;
else
printf(",");
printf("(%d,%s)", i,
old.sa_handler == SIG_IGN ? "Ignored" :
(old.sa_handler == SIG_DFL ? "Default" : "Handled"));
}
}
printf("]}");
return 0;
}
|