-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10a.c
More file actions
41 lines (35 loc) · 901 Bytes
/
10a.c
File metadata and controls
41 lines (35 loc) · 901 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
35
36
37
38
39
40
41
/*
============================================================================
Name : 10a
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>
void segv_handler(int sig)
{
printf("🚨 Caught SIGSEGV (Segmentation Fault)\n");
exit(1);
}
int main()
{
struct sigaction sa;
sa.sa_handler = segv_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sigaction(SIGSEGV, &sa, NULL);
int *ptr = NULL;
*ptr = 42; // Intentional segmentation fault
return 0;
}
/*
Output:
╰─ ./10a ─╯
🚨 Caught SIGSEGV (Segmentation Fault)
*/