Signal Handling Question:
Download Questions PDF

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

Linux Signal Handling Interview Question
Linux Signal Handling Interview Question

Answer:

d) Parent exits without going to the signal handler

Download Linux Signal Handling Interview Questions And Answers PDF

Previous QuestionNext Question
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
Which signal is generated when we press control-C?
a) SIGINT
b) SIGTERM
c) SIGKILL
d) SIGSEGV