Home »
Aptitude Questions and Answers »
C++ Aptitude Questions and Answers
C++ Signal Handler Aptitude Questions and Answers
C++ Signal Handler Aptitude: This section contains C++ Signal Handler Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on February 20, 2021
1) There are the following statements that are given below, which of them are correct about signals?
- Signals are interrupts that are generated by the operating system in some special conditions or system errors.
- Signals are delivered to the process by the operating system to stop currently running tasks.
- Users can also generate interrupts by pressing some special keyboard keys.
- All the above
Options:
- A and B
- A and C
- B and C
- D
Correct Answer - 4
D
Explanation:
All given statements are correct about signals.
2) Which of the following header file is used to handle signals in C++?
- <csignal>
- <signals>
- <cppsignal>
- <cppsignals>
Correct Answer - 1
<csignal>
Explanation:
The <csignal> header file is used to handle signals in C++.
3) Which of the following correct signals are used in the C++ program?
- SIGINT
- SIGILL
- SIGALARM
- SIGSTOP
Options:
- A and C
- A and D
- A, C, and D
- A, B, C, and D
Correct Answer - 4
A, B, C, and D
Explanation:
All options are correct signals that are used in the C++ program.
4) Which of the following signal is used to send a termination request to the program?
- TERM
- SIGTERMINATE
- SIGTERM
- SIGTER
Correct Answer - 3
SIGTERM
Explanation:
The SIGTERM signal is used to send a termination request to the program.
5) Which of the following signal is used to generate invalid access to the storage?
- SIGISTR
- SIGSEGV
- SIGSTORAGE
- None of the above
Correct Answer - 2
SIGSEGV
Explanation:
The SIGSEGV signal is used to generate invalid access to the storage.
6) Which of the following signal is used to generate some erroneous arithmetic operation like divide by zero?
- SIGFPE
- SIGAER
- SIGDIV
- SIGEXP
Correct Answer - 1
SIGFPE
Explanation:
The SIGFPE signal is used to generate some erroneous arithmetic operation like divide by zero
7) Which of the following signal is used to generate for segmentation violation?
- SIGSEG
- SIGSEGV
- SIGSVOIL
- None of the above
Correct Answer - 2
SIGSEGV
Explanation:
The SIGSEGV signal is used to generate for segmentation violation.
8) Which of the following signal is not the correct signal used in C++?
- SEGUSR1
- SEGUSR3
- SIGCOUNT
- SIGHUP
Correct Answer - 2
SEGUSR3
Explanation:
The SIGUSR3 signal is not the correct signal used in C++.
9) Which of the following signal is used to implement timer in the C++ program?
- SIGTIMER
- SIG_TIMER
- SIGALARM
- None of the above
Correct Answer - 3
SIGALARM
Explanation:
The SIGALARM is used to implement timer in the C++ program.
10) Which of the following statement is correct about signal handler in C++?
- Signal handler is a function to handle signals
- Signal handler is a user-defined structure
- Signal handler is a user-defined class
- None of the above
Correct Answer - 1
Signal handler is a function to handle signals
Explanation:
A signal handler is a function to handle signals in C++.
11) Which of the following function is used to bind a signal handler with a particular signal in C++?
- setsignal()
- signal()
- bindsignal()
- bindhandler()
Correct Answer - 2
signal()
Explanation:
The signal() function is used to bind the signal handler with a particular signal in C++.
12) Which of the following function is used to generate a particular signal explicitly?
- siggen()
- sigcall()
- raise()
- sigraise()
Correct Answer - 3
raise()
Explanation:
The raise() function is used to generate a particular signal explicitly.
13) What is the correct syntax of signal() function in C++?
- void signal(int sig_number, signal signal_handler)
- void signal(signal signal_handler)
- void signal(int sig_number)
- None of the above
Correct Answer - 1
void signal(int sig_number, signal signal_handler)
Explanation:
The 1st option is correct syntax of signal() function.
14) What is the correct output of the following code?
#include <iostream>
#include <csignal>
using namespace std;
sig_atomic_t isSigHandle = 0;
void handler(int mysignal)
{
isSigHandle = 1;
}
int main()
{
signal(SIGINT, handler);
raise(SIGINT);
if (isSigHandle)
cout << "Signal has been handled" << endl;
else
cout << "Signal is not handled" << endl;
return 0;
}
- Signal has been handled
- Signal is not handled
- Syntax error
- Runtime exception
Correct Answer - 1
Signal has been handled
Explanation:
The above code will print "Signal has been handled" on the console screen.
15) What is the correct output of the following code?
#include <iostream>
#include <csignal>
using namespace std;
float isSigHandle = 0.0F;
void handler(int mysignal)
{
isSigHandle = 1.0F;
}
int main()
{
signal(SIGINT, handler);
raise(SIGINT);
if (isSigHandle)
cout << "Signal has been handled" << endl;
else
cout << "Signal is not handled" << endl;
return 0;
}
Options:
- Signal has been handled
- Signal is not handled
- Syntax error
- Runtime exception
Correct Answer - 1
Signal has been handled
Explanation:
The above code will print "Signal has been handled" on the console screen.