linuxprocessoperating-systemsignalsinterrupt

When Are Signals Handled?


I read:

Signals are handled only when the receiving process has returned from kernel mode to user mode.

But that doesn't make sense to me, why?

Theoretically, let's say process A is running and it sent a signal to process B, When process B starts running it might never run in kernel mode those never see the signal and handle it.

But, in real world signals are handled nearly instantly (At least from my own observations), How is this possible as I'm seeing a clear contradiction?


Solution

  • Theoretically, let's say process A is running and it sent a signal to process B, When process B starts running it might never run in kernel mode those never see the signal and handle it.

    Linux is a preemptive multitasking operating system. This means that the kernel gives every process a time slice and the CPU will receive a hardware interrupt in regular time intervals, which will return it to kernel-mode, so that the kernel can, for example, give a time slice to a different process.

    Therefore, the situation you describe (that a process will run forever in user-mode and never reach kernel-mode) will never occur in a preemptive multitasking operating system such as Linux.