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?

  1. Signals are interrupts that are generated by the operating system in some special conditions or system errors.
  2. Signals are delivered to the process by the operating system to stop currently running tasks.
  3. Users can also generate interrupts by pressing some special keyboard keys.
  4. All the above

Options:

  1. A and B
  2. A and C
  3. B and C
  4. D

2) Which of the following header file is used to handle signals in C++?

  1. <csignal>
  2. <signals>
  3. <cppsignal>
  4. <cppsignals>

3) Which of the following correct signals are used in the C++ program?

  1. SIGINT
  2. SIGILL
  3. SIGALARM
  4. SIGSTOP

Options:

  1. A and C
  2. A and D
  3. A, C, and D
  4. A, B, C, and D

4) Which of the following signal is used to send a termination request to the program?

  1. TERM
  2. SIGTERMINATE
  3. SIGTERM
  4. SIGTER

5) Which of the following signal is used to generate invalid access to the storage?

  1. SIGISTR
  2. SIGSEGV
  3. SIGSTORAGE
  4. None of the above

6) Which of the following signal is used to generate some erroneous arithmetic operation like divide by zero?

  1. SIGFPE
  2. SIGAER
  3. SIGDIV
  4. SIGEXP

7) Which of the following signal is used to generate for segmentation violation?

  1. SIGSEG
  2. SIGSEGV
  3. SIGSVOIL
  4. None of the above

8) Which of the following signal is not the correct signal used in C++?

  1. SEGUSR1
  2. SEGUSR3
  3. SIGCOUNT
  4. SIGHUP

9) Which of the following signal is used to implement timer in the C++ program?

  1. SIGTIMER
  2. SIG_TIMER
  3. SIGALARM
  4. None of the above

10) Which of the following statement is correct about signal handler in C++?

  1. Signal handler is a function to handle signals
  2. Signal handler is a user-defined structure
  3. Signal handler is a user-defined class
  4. None of the above

11) Which of the following function is used to bind a signal handler with a particular signal in C++?

  1. setsignal()
  2. signal()
  3. bindsignal()
  4. bindhandler()

12) Which of the following function is used to generate a particular signal explicitly?

  1. siggen()
  2. sigcall()
  3. raise()
  4. sigraise()

13) What is the correct syntax of signal() function in C++?

  1. void signal(int sig_number, signal signal_handler)
  2. void signal(signal signal_handler)
  3. void signal(int sig_number)
  4. None of the above

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;
}
  1. Signal has been handled
  2. Signal is not handled
  3. Syntax error
  4. Runtime exception

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:

  1. Signal has been handled
  2. Signal is not handled
  3. Syntax error
  4. Runtime exception





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.