-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path008f.c
More file actions
46 lines (39 loc) · 1.36 KB
/
008f.c
File metadata and controls
46 lines (39 loc) · 1.36 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
/*
..........................................................................................................................................
Name : 008.c
Author : SHRUTI VERMA
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 : 20 Sep 2025
..........................................................................................................................................
*/
#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
#include<sys/time.h>
void my_handler(int signal) {
if(signal == SIGVTALRM)
printf("Caught SIGVTALRM : Timer Expired\n");
exit(1);
}
int main() {
signal(SIGVTALRM, my_handler);
struct itimerval timer;
timer.it_value.tv_sec = 0;
timer.it_value.tv_usec = 1;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_usec = 10;
setitimer(ITIMER_VIRTUAL, &timer, NULL);
while(1);
return 0;
}
/*----------------------------------OUTPUT----------------------------------------------------------------
Caught SIGVTALRM : Timer Expired
*/