Interrupts, Exceptions, and Context Switching Quiz Quiz

Explore core concepts of interrupts, exceptions, and context switching with this focused quiz. Sharpen your understanding of how CPUs manage processes and handle unexpected events in operating systems and embedded environments.

  1. Types of Interrupts

    Which of the following is considered a hardware interrupt in a typical computer system?

    1. A division by zero error in a program
    2. A keyboard key being pressed
    3. A syntax error during compilation
    4. A system call from a running process

    Explanation: A hardware interrupt is generated by external devices like keyboards or timers when they need attention from the processor. A keyboard key being pressed signals a hardware event, prompting the CPU to respond. A division by zero error is a software exception, a system call is a programmatic request, and a syntax error is detected at compile time, not at runtime, so these do not qualify as hardware interrupts.

  2. Handling Exceptions

    When a program attempts to access memory it does not have permission to, what typically occurs?

    1. A hardware interrupt is sent to the graphics card
    2. The processor silently ignores the violation and allows the program to continue
    3. An exception is raised and the operating system may terminate the process
    4. The program automatically corrects the address and retries

    Explanation: Accessing unauthorized memory causes an exception (often a segmentation fault or access violation), and the operating system usually intervenes, possibly terminating the offending process. Processors do not simply ignore such violations; doing so would threaten system stability. No hardware interrupt is directed to the graphics card in this scenario, and the program cannot autonomously correct illegal memory access without explicit logic.

  3. Purpose of Context Switching

    Why is context switching essential in a multitasking operating system?

    1. It ensures that only one program can run at any given moment
    2. It prevents hardware interrupts from being processed
    3. It allows the CPU to fairly share its time among multiple processes
    4. It increases the clock speed of the processor

    Explanation: Context switching lets the CPU rapidly change from one process to another, giving each process a chance to execute and ensuring fairness in CPU utilization. It does not block hardware interrupts—handling interrupts often triggers a context switch. The purpose is not to enforce single-tasking or to increase processor speed, but rather to enable multitasking capability.

  4. Exception Vector Table Usage

    What is the primary role of an exception vector table in a CPU architecture?

    1. It stores the addresses of exception handling routines
    2. It manages user passwords during boot
    3. It allocates memory for new user processes
    4. It records the history of all executed instructions

    Explanation: The exception vector table maps various exception types to their corresponding handling routines, ensuring quick and accurate responses when exceptions occur. Managing user passwords is unrelated, and recording executed instructions is the job of other system components (e.g., tracers or debuggers). Memory allocation for processes does not involve exception vector tables.

  5. Order of Context Saving

    Which step is typically performed first by the CPU when a context switch is triggered by an interrupt?

    1. The new process is immediately scheduled without saving any data
    2. The current values of registers are saved to memory
    3. The interrupt flag is disabled after the switch
    4. All loaded device drivers are reinstalled

    Explanation: Saving register values preserves the current state of the running process, allowing it to resume later without loss of data. Skipping this step would result in corrupted process states. Reinstalling device drivers is unnecessary during a switch, and disabling the interrupt flag might occur as a secondary step for critical section protection, but is not done after the switch.