Signal Handling Question:

Download Job Interview Questions and Answers PDF

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

Linux Signal Handling Interview Question
Linux Signal Handling Interview Question

Answer:

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]#

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>

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
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