Signals exampe, sigaction included
This commit is contained in:
parent
f3522129a3
commit
080928d3fd
3 changed files with 64 additions and 0 deletions
23
signals/main_sigaction.c
Normal file
23
signals/main_sigaction.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void handler(int sig) {
|
||||
write(1, "Caught SIGINT\n", 14); // Async-signal-safe output
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct sigaction sa;
|
||||
sa.sa_handler = handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
|
||||
sigaction(SIGINT, &sa, NULL);
|
||||
|
||||
while (1) {
|
||||
printf("Running...\n");
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue