Signal Handling Interview Questions And Answers
Download Linux Signal Handling Interview Questions and Answers PDF
Strengthen your Linux Signal Handling interview skills with our collection of 21 important questions. Our questions cover a wide range of topics in Linux Signal Handling to ensure you're well-prepared. Whether you're new to the field or have years of experience, these questions are designed to help you succeed. Get the free PDF download to access all 21 questions and excel in your Linux Signal Handling interview. This comprehensive guide is essential for effective study and confidence building.
21 Linux Signal Handling Questions and Answers:
Linux Signal Handling Job Interview Questions Table of Contents:
1 :: Which signal is generated when we press control-C?
a) SIGINT
b) SIGTERM
c) SIGKILL
d) SIGSEGV
a) SIGINT
Read More2 :: If a signal is received by a process, when will it be processed?
a) It is processed immediately
b) It is processed when process is switching to kernel mode
c) It is processsed in the next timeslice given to the process
b) It is processed when process is switching to kernel mode
Read More3 :: Which signal is generated when we press ctrl-Z?
a) SIGKILL
b) SIGSTOP
c) SIGABRT
d) SIGINT
d) SIGINT
Read More4 :: Which signal is sent when the Child process terminates?
a) SIGINIT
b) SIGKILL
c) SIGSTOP
d) SIGCHLD
b) SIGKILL
Read More5 :: Which of the following signal cannot be handled or ignored?
a) SIGINT
b) SIGCHLD
c) SIGKILL
d) SIGALRM
c) SIGKILL
Read More6 :: 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
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]#
Read MoreOutput:
[root@localhost sigaction]# gcc -o san san.c
[root@localhost sigaction]# ./san
^CLinux
^CLinux
^Z
[7]+ Stopped ./san
[root@localhost google]#
7 :: 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
b) "Alarm clock"
Explanation:After 5 seconds of the execution of this program, the signal SIGALRM hits the process and handler executes.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Alarm clock
[root@localhost google]#
Read MoreExplanation:After 5 seconds of the execution of this program, the signal SIGALRM hits the process and handler executes.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Alarm clock
[root@localhost google]#
8 :: 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
a) the child process kills the parent process
Explanation:
The SIGKILL signal can not be handled by singal handler function.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Killed
[root@localhost google]# I am an orphan process because my parent has been killed by me
Handler failed
[root@localhost google]#
Read MoreExplanation:
The SIGKILL signal can not be handled by singal handler function.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Killed
[root@localhost google]# I am an orphan process because my parent has been killed by me
Handler failed
[root@localhost google]#
9 :: 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
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]#
Read MoreExplanation:
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]#
10 :: 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
b) this program will print "Child Exited"
Explanation:
The child process sends SIGCHILD signal to its parent as it terminates.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Child exited
[root@localhost google]#
Read MoreExplanation:
The child process sends SIGCHILD signal to its parent as it terminates.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Child exited
[root@localhost google]#
11 :: In this program
#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
int main()
{
pid_t child;
child=fork();
switch(child){
case -1 :
perror("fork");
exit(1);
case 0 :
while(1){
printf("Child Processn");
sleep(1);
}
break;
default :
sleep(5);
kill(child,SIGINT);
printf("The child process has been killed by the parent processn");
break;
}
return 0;
}
a) the child process kills the parent process
b) the parent process kills the child process
c) both the processes are killed by each other
d) none of the mentioned
b) the parent process kills the child process
Explanation:
The parnet process kills the child by sending a signal.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Child Process
Child Process
Child Process
Child Process
Child Process
The child process has been killed by the parent process
[root@localhost google]#
Read MoreExplanation:
The parnet process kills the child by sending a signal.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Child Process
Child Process
Child Process
Child Process
Child Process
The child process has been killed by the parent process
[root@localhost google]#
12 :: What will print as the SIGINT signal hits the running process of this program?
#include<stdio.h>
#include<stdlib.h>
#include<signal.h>
void response (int);
void response (int sig_no)
{
printf("%s",sys_siglist[sig_no]);
}
int main()
{
signal(SIGINT,response);
while(1){
printf("googlen");
sleep(1);
}
return 0;
}
a) Interrupt
b) Stop
c) Terminate
d) none of the mentioned
a) Interrupt
Explanation:
The messages associated with signals can be access by the function sys_siglist().
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
google
google
google
^CInterruptgoogle
google
^CInterruptgoogle
google
^CInterruptgoogle
google
google
^Z
[4]+ Stopped ./san
[root@localhost google]#
Read MoreExplanation:
The messages associated with signals can be access by the function sys_siglist().
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
^CInterruptgoogle
^CInterruptgoogle
^CInterruptgoogle
^Z
[4]+ Stopped ./san
[root@localhost google]#
13 :: What happens as the SIGINT signal hits the running process of this program?
#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
int main()
{
pid_t child;
signal(SIGINT,SIG_IGN);
child=fork();
switch(child){
case -1:
perror("fork");
exit(1);
case 0:
while(1){
printf("Child Processn");
sleep(1);
}
break;
default :
while(1){
printf("Parent Processn");
pause();
}
break;
}
return 0;
}
a) child process terminates
b) parent process terminates
c) both child and parent process ignores the signal
d) none of the mentioned
c) both child and parent process ignores the signal
Explanation:
If a process ignores a signal then by default its child also ignores that signal.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Parent Process
Child Process
Child Process
^CChild Process
^CChild Process
^CChild Process
^Z
[3]+ Stopped ./san
[root@localhost signal]#
Read MoreExplanation:
If a process ignores a signal then by default its child also ignores that signal.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
Parent Process
Child Process
Child Process
^CChild Process
^CChild Process
^CChild Process
^Z
[3]+ Stopped ./san
[root@localhost signal]#
14 :: What will happen if we press "Ctrl+c" key two times after running this program?
#include<stdio.h>
#include<signal.h>
void response(int);
void response(int sig_no)
{
printf("Linuxn");
signal(SIGINT,SIG_DFL);
}
int main()
{
signal(SIGINT,response);
while(1){
printf("googlen");
sleep(1);
}
return 0;
}
a) process will terminate in the first time
b) process will terminate in the second time
c) process will never terminate
d) none of the mentioned
c) process will never terminate
Explanation:
According to the signal handler function of this program as the SIGINT signal arrives second time, the signal performs its default operation i.e. termination of the process.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
google
google
^CLinux
google
^C
[root@localhost google]#
Read MoreExplanation:
According to the signal handler function of this program as the SIGINT signal arrives second time, the signal performs its default operation i.e. termination of the process.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
^CLinux
^C
[root@localhost google]#
15 :: What will happen as we press the "Ctrl+c" key after running this program?
#include<stdio.h>
#include<signal.h>
void response (int);
void response (int sig_no)
{
printf("Linuxn");
}
int main()
{
signal(SIGINT,response);
while(1){
printf("googlen");
sleep(1);
}
return 0;
}
a) the string "Linux" will print
b) the process will be terminated after printing the string "Linux"
c) the process will terminate
d) none of the mentioned
a) the string "Linux" will print
Explanation:
The signal handler function "response" executes after recieving the signal SIGINT.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
google
google
google
^CLinux
google
google
^CLinux
google
google
^CLinux
google
^Z
[2]+ Stopped ./san
[root@localhost google]#
Read MoreExplanation:
The signal handler function "response" executes after recieving the signal SIGINT.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
^CLinux
^CLinux
^CLinux
^Z
[2]+ Stopped ./san
[root@localhost google]#
16 :: Another signal that cannot be caught is:
a) SIGPIPE
b) SIGHUP
c) SIGSTOP
d) SIGUSR1
c) SIGSTOP
Read More17 :: When real interval timer expires which signal is generated?
a) SIGINT
b) SIGCHLD
c) SIGKILL
d) SIGALRM
d) SIGALRM
Read More18 :: Signals are handled using which system call?
a) kill
b) signal
c) both
d) none
b) signal
Read More20 :: The kill system call is used to:
a) Send shutdown messages to all by superuser
b) Send a signal to a process
c) Kill processes
d) Stop the processes
b) Send a signal to a process
Read More21 :: What is the output of the below code?
void sig_handler ( int signum) {
printf("Handled the signaln");
}
int main() {
int pid;
signal (SIGKILL, sig_handler);
pid = fork();
if (pid==0) {
kill(getppid(), SIGKILL);
exit(0);
} else {
sleep(20);
}
return 0;
}
a) Error child cannot send a SIGKILL signal to parent.
b) Parent goes to the signal handler, prints handled the signal and goes back to sleep
c) Parent goes to the signal handler, prints handled the signal and exits
d) Parent exits without going to the signal handler
d) Parent exits without going to the signal handler
Read More