Interviewer And Interviewee Guide

Signal Handling Interview 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

Submitted by: Murtaza
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]#
Submitted by: Murtaza

Read Online Signal Handling Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.