.
This commit is contained in:
33
bac2/os/chap1/ex2.c
Normal file
33
bac2/os/chap1/ex2.c
Normal file
@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
Reference in New Issue
Block a user