Skip to content

Commit 1a45d3d

Browse files
committed
q1_signal_handler
1 parent 3e38dec commit 1a45d3d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lab7_question1_signal.c

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#include <stdio.h>
3+
#include <string.h>
4+
#include <unistd.h>
5+
#include <sys/types.h>
6+
#include <signal.h>
7+
// "handler1" is handler function for action1
8+
int c=0;
9+
void handler1(int signo){
10+
switch(signo){
11+
case SIGINT:
12+
printf("Interrupt Signal received \n");
13+
c++;
14+
break;
15+
}
16+
}
17+
int main()
18+
{
19+
while(1){
20+
//initializing sigaction structure
21+
struct sigaction action1;
22+
action1.sa_handler = handler1;
23+
action1.sa_flags = 0;
24+
sigaction(SIGINT,(struct sigaction *) &action1,NULL);
25+
//runnign forever, while process is sensitive to SIGINT
26+
if(c==5){
27+
break;
28+
}
29+
}
30+
return 0;
31+
}

0 commit comments

Comments
 (0)