What is the difference between user and kernel modes in operating systems?

后端 未结 7 1893
长发绾君心
长发绾君心 2020-12-02 04:31

What are the differences between User Mode and Kernel Mode, why and how do you activate either of them, and what are their use cases?

相关标签:
7条回答
  • 2020-12-02 05:07

    These are two different modes in which your computer can operate. Prior to this, when computers were like a big room, if something crashes – it halts the whole computer. So computer architects decide to change it. Modern microprocessors implement in hardware at least 2 different states.

    User mode:

    • mode where all user programs execute. It does not have access to RAM and hardware. The reason for this is because if all programs ran in kernel mode, they would be able to overwrite each other’s memory. If it needs to access any of these features – it makes a call to the underlying API. Each process started by windows except of system process runs in user mode.

    Kernel mode:

    • mode where all kernel programs execute (different drivers). It has access to every resource and underlying hardware. Any CPU instruction can be executed and every memory address can be accessed. This mode is reserved for drivers which operate on the lowest level

    How the switch occurs.

    The switch from user mode to kernel mode is not done automatically by CPU. CPU is interrupted by interrupts (timers, keyboard, I/O). When interrupt occurs, CPU stops executing the current running program, switch to kernel mode, executes interrupt handler. This handler saves the state of CPU, performs its operations, restore the state and returns to user mode.

    http://en.wikibooks.org/wiki/Windows_Programming/User_Mode_vs_Kernel_Mode

    http://tldp.org/HOWTO/KernelAnalysis-HOWTO-3.html

    http://en.wikipedia.org/wiki/Direct_memory_access

    http://en.wikipedia.org/wiki/Interrupt_request

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