-
Notifications
You must be signed in to change notification settings - Fork 0
/
sigaction.c
55 lines (49 loc) · 1.4 KB
/
sigaction.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 <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#define NSTACK 100
volatile int waiting_pid;
pid_t pid_stack[NSTACK];
int count=0;
void sig_ign(struct sigaction* act){
act->sa_sigaction = NULL;
act->sa_handler = SIG_IGN;
sigset_t sigset;
int sigem;
if((sigem=sigemptyset(&sigset))<0){perror("sigemptyset error");exit(1);}
act->sa_mask= sigset;
act->sa_flags=0;
act->sa_restorer=NULL;
}
void sig_ign_drop(struct sigaction* act){
act->sa_sigaction = NULL;
act->sa_handler = SIG_DFL;
sigset_t sigset;
int sigem;
if((sigem=sigemptyset(&sigset))<0){perror("sigemptyset error");exit(1);}
act->sa_mask=sigset;
act->sa_flags=0;
act->sa_restorer=NULL;
}
void wait_child(int signal,siginfo_t* info,void* ctx){
if(info->si_code==CLD_STOPPED){
pid_stack[count] = info->si_pid;
count++;
}
if(info->si_code != CLD_CONTINUED){
int wstatus;
if ((waiting_pid = waitpid(info->si_pid,&wstatus, WUNTRACED))<0){perror("waitchild error");}
}
//printf("accepted"); //For debug(NOT RECOMMENDED)
}
void sig_wait_child(struct sigaction*act){
act->sa_handler = NULL;
act->sa_sigaction = wait_child;
sigset_t sigset;
int sigem;
if((sigem=sigemptyset(&sigset))<0){perror("sigemptyset error");exit(1);}
act->sa_mask=sigset;
act->sa_flags = SA_SIGINFO;
act->sa_restorer = NULL;
}