Difference between User Mode and Kernel Mode

Learn via video courses
Topics Covered

Overview

There are two modes found in modern operating systems that are user mode and kernel mode. User mode has some limited access to the system resources while kernel mode has more access to the system resources. Also, the modern operating system keeps switching between these two modes to execute a process efficiently and maintain the system security. In this article, you will see what is user mode and kernel mode, the difference between user mode and kernel mode, and various aspects of it. Before moving to their differences, let us discuss these two modes separately.

What is User Mode?

Whenever you run an application in your computer system, it runs in the user mode. For example, if you are running MS Word, or watching some video using the VLC Player, all these software applications are running in the user mode. When opening the program in user mode, it is not allowed to access the RAM and hardware directly. To access the hardware and RAM in user mode, it sends a request to the kernel. That is the reason user mode is also known as slave mode, or restricted mode. Running a program in user mode does not have its own address space and thus also it is unable to access the address space of the kernel. That is why if there is any program failure in user mode, it does not affect the other processes. It only affects that particular process where an interrupt occurs.

what is user mode

If an application running under user mode and it wants to access system resources and hardware, it will have to first go through the Operating system Kernel by using syscalls (system calls). The mode bit is set to 1 in user mode and while switching from user mode to kernel mode, this mode bit is set to 0.

What is Kernel Mode?

When we start our system, it boots in Kernel mode. The kernel can access the hardware and RAM of the system directly. There are some privileged instructions that can run in the kernel mode only. These instructions are interrupt instructions, input-output management, etc. If these privileged instructions get executed under the user mode, it is not legal and it may cause an illegal trap.

what is kernel mode

In kernel mode, the mode bit is set to 0. And when switching from kernel mode to user mode, the bit mode is changed from 0 to 1. When the mode changes from user mode to kernel mode or vice-versa, it is known as Context Switching.

Kernel is the central module of the operating system and it works as the middle layer between the operating system and the hardware of a system. Operating systems maintain control over the computer system by utilizing the kernel of an operating system as a means of communication. The kernel handles the remaining system functions on behalf of the operating system, hence it is the first software to load into memory when a system boots up after the bootloader. The kernel is in the memory of the system until the operating system shuts down the system. There are various types of kernels in an operating system. To learn more about Kernel in detail, click here.

Need of Dual Mode (User mode and Kernel Mode)

There is a need for both the user mode and kernel mode in our system. The reasons behind this are as follows:

  • When running a user program such as MS Word, or File Manager can be mistakenly erased the operating system by overwriting it with the user data.
  • When there is multiple program running in the same system at the same time can cause disastrous results.

To learn more about the terminologies related to operating system, go to the- glossary for operating system.

Difference between User Mode and Kernel Mode

CriteriaKernel ModeUser Mode
Resource AccessThere is direct access to the RAM and hardware in the kernel mode.There is no direct access to the RAM and hardware in the kernel mode. To access the hardware and RAM in kernel mode, there is a need to make a system call.
ModesKernel mode is also known by some other names such as master mode, privileged mode, and system mode.User mode is also known by other names such as unprivileged mode, slave mode, and restricted mode.
Privilege LevelIn kernel mode, the software and applications have more privilege to access the system resources such as RAM or hardware.In user mode, the software and applications have comparatively less privilege to access the system resources such as RAM or hardware.
Virtual Address SpaceIn kernel mode, all the processes and requests share the same virtual address space.In user mode, all the processes and requests share a separate virtual address space.
RestrictionsIn kernel mode, there are no restrictions. You can access both the user program and kernel programs.In user mode, there are restrictions for this. You can not access both the user program and kernel programs directly. You need to use a system call for this access.
Mode Bit ValueIn kernel mode, the mode bit is set to 0.In user mode, the mode bit is set to 1
InterruptionsIn kernel there is the probability of getting the whole system shut down if any interruption occurs during the process execution.In user mode, a single process failure does not lead to a hole system shut down. Only that specific process fails.
System CrashIn kernel mode, a single system crash may lead to complicated problems.In user mode, a single system crash does not affect the whole system process. It can be also recovered by resuming the task session.
FunctionalityAs we know the kernel mode is able to refer to any memory block in the computer system and it can access the resources directly to execute a process that makes this mode a very potent and important mode for the users.User mode is a very basic and standard viewing mode. It means that this mode can not access the hardware and RAM that makes it to execute the process on its own. It uses an Application Protocol Interface API for this purpose.

Which One to Choose?

In a system, the process gets executed in both kernel mode and user mode. As we know the use mode does not have direct access to the hardware and RAM of the system. But kernel mode can have direct access to the RAM and hardware of the system. Before choosing any one form of user mode and kernel mode it is important to know that kernel mode has more power and access that helps them to execute even complex tasks easier. However, this is not the case with the user interface.

Many time system keep switching between the user mode and kernel mode. So, it is the best option to use dual mode (kernel and user mode) and keep switching between them. The temporary switching between the kernel mode and user mode is termed context switching.

FAQs

Q. Why do we need dual mode in the operating system?

A. By using these two types together, we get extra stability and protection in our computer system as user mode has limited access and kernel mode has full access to the RAM and system hardware.

Q. What is the transition from the user mode and kernel mode in the operating system?

A. The switching between these two is done using SCI (System Call Interfaces). It helps to make an interruption and switch between user mode and kernel mode.

Q. Which mode is faster kernel mode or user mode?

A. Kernel mode drivers run in the same memory space as the operating system kernel, which means that kernel mode drivers have direct access to the hardware and can perform faster and more efficiently than user mode drivers.

Conclusion

  • Whenever you run an application such as MS Word, File Explorer, etc. in your computer system, it runs in the user mode, and opening the program in user mode, it is not allowed to access the RAM and hardware directly.
  • The system call is defined as the way of establishing an interaction between the operating system and the hardware.
  • Interrupts are defined as the signal that is sent by either hardware or software when immediate attention by a process is required.
  • Context switching is a process in the operating system in which the context or state of a process is stored for a short period so that it can be fetched again if there is a requirement of this context again during the execution of a task.
  • In kernel mode, all the processes and requests share the same virtual address space but in user mode, all the processes and requests share a separate virtual address space.