What is user mode vs. kernel mode in an operating system?

Modern operating systems have two basic modes in which they can execute a certain program: the user-mode and the kernel-mode. The distinction between these two modes allows modern operating systems to continue their operation even if one of the running applications misbehaves. Without this separation between the modes, processes running on the system might interfere with each other, e.g., by overwriting each other’s memory addresses and cause the whole system to halt.

User mode

Every user process operates under the user mode. In this mode, processes do not have direct access to the RAM or other hardware resources and have to make system calls to the underlying APIs to access these resources.

Kernel mode

The system starts in the kernel mode when it boots up. The kernel mode has direct access to all the underlying hardware resources. In the kernel mode, all memory addresses are accessible and all CPU instructions are executable.

Kernel mode is usually reserved for drivers which need finer control over the hardware they are operating on.

Moving between the user mode and the kernel mode is referred to as context switching. Context switching occurs when a user process makes a request to the underlying system API. The switch does not occur automatically; rather, an interrupt is generated. An interrupt handler then saves the state of the CPU, switches to the kernel mode where the CPU can execute the instructions, and then restores the state of the CPU and returns to user mode.

Copyright ©2024 Educative, Inc. All rights reserved