cours_progra/bac2/os/chap1/ex2.c
Debucquoy b0f02b0d5d
.
2023-10-18 20:27:40 +02:00

34 lines
588 B
C

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
typedef struct sigaction SIGS;
uint8_t kill_counter = 0;
const char* sentences[] = {
"Just give me a moment.",
"I said I need a moment!",
"Fine. I'm out of here....",
};
void handler(int sig, siginfo_t* info, void* context) {
printf("%s\n", sentences[kill_counter++]);
if(kill_counter >= 3)
abort();
}
int main(int argc, char *argv[])
{
SIGS event = {
.sa_sigaction = handler,
.sa_flags = SA_SIGINFO
};
sigaction(SIGINT, &event, NULL);
while(1)
pause();
return 0;
}