-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10b.c
More file actions
51 lines (44 loc) Β· 1.12 KB
/
10b.c
File metadata and controls
51 lines (44 loc) Β· 1.12 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
============================================================================
Name : 10b
Author : Piyush Singh
Description : Write a separate program using sigaction system call to catch the following signals.
a. SIGSEGV
b. SIGINT
c. SIGFPE
Date: 19th Sep, 2025.
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void sigint_handler(int sig)
{
printf(" π Caught SIGINT (Ctrl+C)\n");
exit(0);
}
int main()
{
struct sigaction sa;
sa.sa_handler = sigint_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGINT, &sa, NULL);
while (1)
{
printf("β Waiting... Press Ctrl+C to interrupt\n");
sleep(2);
}
return 0;
}
/*
Output:
β°β ./10b ββ―
β Waiting... Press Ctrl+C to interrupt
β Waiting... Press Ctrl+C to interrupt
β Waiting... Press Ctrl+C to interrupt
β Waiting... Press Ctrl+C to interrupt
β Waiting... Press Ctrl+C to interrupt
^Cπ Caught SIGINT (Ctrl+C)
*/