-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignal_test.c
54 lines (41 loc) · 970 Bytes
/
signal_test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
int main()
{
int nSigno = 0;
sigset_t nSigset;
sigemptyset( &nSigset );
sigaddset( &nSigset, SIGINT );
sigaddset( &nSigset, SIGUSR1 );
sigaddset( &nSigset, SIGRTMIN );
sigaddset( &nSigset, SIGRTMIN+1 );
if( sigprocmask( SIG_BLOCK, &nSigset, NULL) < 0 ){
perror( "sigprocmask()" );
exit( EXIT_FAILURE );
}
struct sigaction strSigact;
memset(&strSigact,0x00,sizeof(strSigact));
strSigact.sa_handler = SIG_IGN;
sigaction(SIGCHLD,&strSigact,NULL);
sigaction(SIGPIPE,&strSigact,NULL);
FILE *fp = NULL;
fp = popen("ls","w");
char buff[128] = {0};
fgets(buff,sizeof(buff),fp);
puts(buff);
while(1){
sleep(3);
puts( "sigwait blocking..." );
if( !sigwait( &nSigset, &nSigno ) ){
printf("catch Signal. [%s]\n", strsignal(nSigno) );
} else {
perror( "sigwait()" );
exit( EXIT_FAILURE );
}
}
exit( EXIT_SUCCESS );
}