What is the difference between the kernel space and the user space?

前端 未结 16 1276
渐次进展
渐次进展 2020-11-30 16:28

What is the difference between the kernel space and the user space? Do kernel space, kernel threads, kernel processes and kernel stack mean the same thing? Also, why do we n

16条回答
  •  情歌与酒
    2020-11-30 16:44

    Kernel Space and User Space are logical spaces.

    Most of the modern processors are designed to run in different privileged mode. x86 machines can run in 4 different privileged modes.

    And a particular machine instruction can be executed when in/above particular privileged mode.

    Because of this design you are giving a system protection or sand-boxing the execution environment.

    Kernel is a piece of code, which manages your hardware and provide system abstraction. So it needs to have access for all the machine instruction. And it is most trusted piece of software. So i should be executed with the highest privilege. And Ring level 0 is the most privileged mode. So Ring Level 0 is also called as Kernel Mode.

    User Application are piece of software which comes from any third party vendor, and you can't completely trust them. Someone with malicious intent can write a code to crash your system if he had complete access to all the machine instruction. So application should be provided with access to limited set of instructions. And Ring Level 3 is the least privileged mode. So all your application run in that mode. Hence that Ring Level 3 is also called User Mode.

    Note: I am not getting Ring Levels 1 and 2. They are basically modes with intermediate privilege. So may be device driver code are executed with this privilege. AFAIK, linux uses only Ring Level 0 and 3 for kernel code execution and user application respectively.

    So any operation happening in kernel mode can be considered as kernel space. And any operation happening in user mode can be considered as user space.

提交回复
热议问题