-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSigAction.c
More file actions
executable file
·34 lines (28 loc) · 863 Bytes
/
Copy pathSigAction.c
File metadata and controls
executable file
·34 lines (28 loc) · 863 Bytes
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
//
// Created by tw on 2018/3/2.
//
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include "Practical.h"
void InterruptSignalHandler(int signalType);
int main(int argc, char *arv[]) {
struct sigaction handler;
//Set InterruptSignalHandler() as handler function
handler.sa_handler = InterruptSignalHandler;
//Create mask that blocks all signals
if (sigfillset(&handler.sa_mask) < 0)
DieWithSystemMessage("sigfillset() failed");
handler.sa_flags = 0;
//Set signal handling for interrupt signal
if (sigaction(SIGINT, &handler, 0) < 0)
DieWithSystemMessage("sigaction() failed for SIGINT");
for (;;)
pause();
exit(0);
}
void InterruptSignalHandler(int signalType) {
puts("Interrupt Received. Exiting program");
exit(1);
}