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 60 61 62 63 64 65 66
|
void handler(int sig);
int main(int argc, char **argv){
pid_t pid = 0;
int k = atoi(argv[1]);
int nb_sig = argc-2;
int sigs[nb_sig];
struct sigaction action;
action.sa_handler = handler;
action.sa_flags = 0;
sigset_t ens, avant;
sigemptyset(&ens);
sigaddset(&ens, 10);
sigprocmask(SIG_BLOCK, &ens, &avant);
for(int i = 0; i < nb_sig; i++){
sigs[i] = atoi(argv[i+2]);
}
pid = fork();
if(!pid){
for(int i = 0; i < k; i++){
for(int j = 0; j < nb_sig; j++){
printf("Fils----> Envoi du signal %d au pid = %d\n", sigs[j], getppid());
kill(getppid(), sigs[j]);
sigsuspend(&ens);
sigaction(SIGUSR1, &action, NULL);
}
}
}
else{
struct sigaction action;
action.sa_handler = handler;
action.sa_flags = 0;
sigemptyset(&action.sa_mask);
for(int i = 0; i < NSIG; i++){
if(sigaction(i, &action, NULL)!= -1){
kill(pid, 10);
}
}
while(1);
}
return EXIT_SUCCESS;
}
/**
*
*/
void handler(int sig){
if(sig == 10){
printf("Fils--> Reception de l'acquittement \n");
}
else{
printf("Pere--->reception du signal %d\n ", sig);
}
} |
Partager