Signal Handling Question:
Download Questions PDF

What happnes as the signal SIGINT hits the current process in the program?

#include<stdio.h>
#include<signal.h>

void response (int);
void response (int sig_no)
{
printf("Linuxn");
}
int main()
{
struct sigaction act;
act.sa_handler = response;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(SIGINT,&act,0);
while(1){
printf("googlen");
sleep(1);
}
return 0;
}
a) the process terminates
b) the string "Linux" prints
c) the string "Linux" prints and then process terminates
d) none of the mentioned

Answer:

b) the string "Linux" prints
Output:
[root@localhost sigaction]# gcc -o san san.c
[root@localhost sigaction]# ./san
google
google
google
^CLinux
google
google
^CLinux
google
^Z
[7]+ Stopped ./san
[root@localhost google]#

Download Linux Signal Handling Interview Questions And Answers PDF

Previous QuestionNext Question
Which of the following signal cannot be handled or ignored?
a) SIGINT
b) SIGCHLD
c) SIGKILL
d) SIGALRM
This program will print:

#include<stdio.h>
#include<signal.h>
#include<unistd.h>

void response (int);
void response (int sig_no)
{
printf("%s is workingn",sys_siglist[sig_no]);
}
int main()
{
alarm(5);
sleep(50);
printf("googlen");
signal(SIGALRM,response);
return 0;
}
a) "google"
b) "Alarm clock"
c) nothing
d) none of the mentioned