0
votes

In my text-book , context-switch doesn't imply mode switch only because there are threads that run only in kernel mode.

Is it true that a context switch can happen only if cpu is running in kernel mode?

If not ,why? Is it true for Unix-like operating system ?

Finally , is it true that all interrupts can be handled only by interrupt handlers that are always executed in kernel mode?

1

1 Answers

1
votes

Interrupts, traps and exceptions may occur when the CPU is executing in user mode. They typically cause the CPU to switch to kernel mode. That may switch the context partially or completely. For example, x86 CPUs may have tasks (yes, tasks inside the CPU) dedicated to handling of interrupts and exceptions, and so if those are in use, there can be a context switch to and from those tasks.

Normally, interrupt handlers run in kernel mode. However, the CPU and/or the OS may handle them partially or entirely in user mode. It depends on the CPU and the OS.