2

I read this answer and I thought that I got a clear idea. But then this answer is confusing me again.

Can somebody please give me a clear picture of the differences between Signal, exception, hardware interrupts and traps?

Moreover, I would like to know which among these block CPU preemption of the kernel code?

Examples would be helpful.

Raman
  • 2,625
  • 1
  • 24
  • 46

1 Answers1

3

Interrupts are generated by hardware. Example: interrupt generated by keyboard to type a character on screen. These are asynchronous in nature which means the processor is unaware when the interrupt will be generated. These are also called hardware interrupts.

Exceptions: These are interrupts which are generated by the processor. Example: Divide by zero. These are synchronous in nature which means processor is aware of interrupt generation.

Traps: are basically an instruction which tells the kernel to switch to kernel mode from user mode. Example: during a system call, a TRAP instruction would force kernel to execute the system call code inside kernel (kernel mode) on behalf of the process. Trap and exception are often used interchangeably.

Signals: signals are generated by kernel and sent to the process in the event of an exception. E.g., a divide by zero instruction would result in kernel generating SIGSEGV signal (segfault) for the process.

bitbyter
  • 671
  • 6
  • 14
  • 3
    1. Interrupts can be issued by hardware. 2. Exceptions aren't synchronous. 3. All things can trap to kernel. 4. Signals aren't always generated by the kernel (process-process signaling happens too). – AleksandrH Sep 06 '18 at 18:36