-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignal_test2.c
More file actions
59 lines (39 loc) · 833 Bytes
/
signal_test2.c
File metadata and controls
59 lines (39 loc) · 833 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
static sigset_t gnSigset;
void handler( int nSigno )
{
printf( "Interrupt occurred. [%s]\n", strsignal( nSigno ) );
return;
}
void _DI( void )
{
sigprocmask( SIG_BLOCK, &gnSigset, NULL);
}
void _EI( void )
{
sigprocmask( SIG_UNBLOCK, &gnSigset, NULL);
}
int main()
{
unsigned char szBuff[128];
struct sigaction strSigact;
sigemptyset( &gnSigset );
sigaddset( &gnSigset, SIGRTMIN );
memset( &strSigact, 0x00, sizeof(strSigact) );
strSigact.sa_handler = handler;
strSigact.sa_mask = gnSigset;
sigaction( SIGRTMIN, &strSigact, NULL );
while(1){
_EI();
read( STDIN_FILENO, szBuff, sizeof(szBuff) );
_DI();
printf( "return read()...\n" );
sleep(5);
}
exit( EXIT_SUCCESS );
}