cours_progra/bac2/os/chap1/ex1.c

35 lines
610 B
C
Raw Normal View History

2023-09-21 08:24:22 +02:00
#include <bits/types/siginfo_t.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct sigaction SIGS;
int counter = 0;
void handler(int sig, siginfo_t* info, void* context) {
if (sig == SIGUSR1){
counter++;
printf("Hello!\n");
}else if ( sig == SIGUSR2 ){
printf("%d\n", counter);
abort();
}
}
int main(int argc, char *argv[]){
2023-10-18 20:27:40 +02:00
2023-09-21 08:24:22 +02:00
SIGS context = {.sa_flags = SA_SIGINFO, .sa_sigaction = handler};
2023-10-18 20:27:40 +02:00
sigaction(SIGUSR1, &context, NULL);
sigaction(SIGUSR2, &context, NULL);
while(1){
printf("The program is running...\n");
sleep(1);
}
2023-09-21 08:24:22 +02:00
return 0;
}
2023-09-20 15:18:20 +02:00