-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8d.c
More file actions
49 lines (43 loc) · 1.04 KB
/
8d.c
File metadata and controls
49 lines (43 loc) · 1.04 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
/*
============================================================================
Name : 8d
Author : Piyush Singh
Description : Write a separate program using signal system call to catch the following signals.
a. SIGSEGV
b. SIGINT
c. SIGFPE
d. SIGALRM (use alarm system call)
e. SIGALRM (use setitimer system call)
f. SIGVTALRM (use setitimer system call)
g. SIGPROF (use setitimer system call)
Date: 19th Sep, 2025.
============================================================================
*/
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
void handler(int sig)
{
printf("⏰ Caught SIGALRM (via alarm)\n");
exit(0);
}
int main()
{
signal(SIGALRM, handler);
alarm(3); // Trigger alarm in 3 seconds
while (1)
{
printf("⌛ Waiting for alarm...\n");
sleep(1);
}
return 0;
}
/*
Output:
./8d ─╯
⌛ Waiting for alarm...
⌛ Waiting for alarm...
⌛ Waiting for alarm...
⏰ Caught SIGALRM (via alarm)
*/