Signal Handling Question:
Download Questions PDF

Which one of the following is not true about this program?

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

void response (int);
void response (int signo)
{
printf("%sn",sys_siglist[signo]);
signal(SIGSEGV,SIG_IGN);
}
int main()
{
signal (SIGSEGV,response);
char *str;
*str = 10;
return 0;
}
a) kernel sends SIGSEGV signal to a process as segmentation fault occurs
b) in this process signal handler will execute only one time of recieving the signal SIGSEGV
c) both (a) and (b)
d) none of the mentioned

Linux Signal Handling Interview Question
Linux Signal Handling Interview Question

Answer:

d) none of the mentioned
Explanation:
In this process the segmentation fault occurs because the memory is not allocated to the pointer *str.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Segmentation fault
Segmentation fault (core dumped)
[root@localhost google]#

Download Linux Signal Handling Interview Questions And Answers PDF

Previous QuestionNext Question
What is the output of this program?

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

void response (int);
void response (int sig_no)
{
printf("%sn",sys_siglist[sig_no]);
printf("This is singal handlern");
}
int main()
{
pid_t child;
int status;
child = fork();
switch (child){
case -1 :
perror("fork");
exit (1);
case 0 :
kill(getppid(),SIGKILL);
printf("I am an orphan process because my parent has been killed by men");
printf("Handler failedn");
break;
default :
signal(SIGKILL,response);
wait(&status);
printf("The parent process is still aliven");
break;
}
return 0;
}
a) the child process kills the parent process
b) the parent process kills the child process
c) handler function executes as the signal arrives to the parent process
d) none of the mentioned
What is the output of this program?

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

void response (int);
void response (int sig_no)
{
printf("%sn",sys_siglist[sig_no]);
}
int main()
{
pid_t child;
int status;
child = fork();
switch(child){
case -1:
perror("fork");
case 0:
break;
default :
signal(SIGCHLD,response);
wait(&status);
break;
}
}
a) this program will print nothing
b) this program will print "Child Exited"
c) segmentation fault
d) none of the mentioned