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

前端 未结 16 1221
渐次进展
渐次进展 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:59

    The really simplified answer is that the kernel runs in kernel space, and normal programs run in user space. User space is basically a form of sand-boxing -- it restricts user programs so they can't mess with memory (and other resources) owned by other programs or by the OS kernel. This limits (but usually doesn't entirely eliminate) their ability to do bad things like crashing the machine.

    The kernel is the core of the operating system. It normally has full access to all memory and machine hardware (and everything else on the machine). To keep the machine as stable as possible, you normally want only the most trusted, well-tested code to run in kernel mode/kernel space.

    The stack is just another part of memory, so naturally it's segregated right along with the rest of memory.

    0 讨论(0)
  • 2020-11-30 17:00

    By Sunil Yadav, on Quora:

    The Linux Kernel refers to everything that runs in Kernel mode and is made up of several distinct layers. At the lowest layer, the Kernel interacts with the hardware via the HAL. At the middle level, the UNIX Kernel is divided into 4 distinct areas. The first of the four areas handles character devices, raw and cooked TTY and terminal handling. The second area handles network device drivers, routing protocols and sockets. The third area handles disk device drivers, page and buffer caches, file system, virtual memory, file naming and mapping. The fourth and last area handles process dispatching, scheduling, creation and termination as well as signal handling. Above all this we have the top layer of the Kernel which includes system calls, interrupts and traps. This level serves as the interface to each of the lower level functions. A programmer uses the various system calls and interrupts to interact with the features of the operating system.

    0 讨论(0)
  • 2020-11-30 17:03

    The correct answer is: There is no such thing as kernel space and user space. The processor instruction set has special permissions to set destructive things like the root of the page table map, or access hardware device memory, etc.

    Kernel code has the highest level privileges, and user code the lowest. This prevents user code from crashing the system, modifying other programs, etc.

    Generally kernel code is kept under a different memory map than user code (just as user spaces are kept in different memory maps than each other). This is where the "kernel space" and "user space" terms come from. But that is not a hard and fast rule. For example, since the x86 indirectly requires its interrupt/trap handlers to be mapped at all times, part (or some OSes all) of the kernel must be mapped into user space. Again, this does not mean that such code has user privileges.

    Why is the kernel/user divide necessary? Some designers disagree that it is, in fact, necessary. Microkernel architecture is based on the idea that the highest privileged sections of code should be as small as possible, with all significant operations done in user privileged code. You would need to study why this might be a good idea, it is not a simple concept (and is famous for both having advantages and drawbacks).

    0 讨论(0)
  • 2020-11-30 17:04

    Kernel space and user space is the separation of the privileged operating system functions and the restricted user applications. The separation is necessary to prevent user applications from ransacking your computer. It would be a bad thing if any old user program could start writing random data to your hard drive or read memory from another user program's memory space.

    User space programs cannot access system resources directly so access is handled on the program's behalf by the operating system kernel. The user space programs typically make such requests of the operating system through system calls.

    Kernel threads, processes, stack do not mean the same thing. They are analogous constructs for kernel space as their counterparts in user space.

    0 讨论(0)
提交回复
热议问题