Reputation: 12621
Trying to understand the relationship between the user space and the kernel space. User space programs uses the system calls to interact with the kernel. if I have a program that reads a data from the file. Then the binary at the user space is executed as well the kernel space is executed. Is it that we have two processes executing one on kernel and the other on user space or is it a single process that runs on both user and kernel.
Upvotes: 0
Views: 2707
Reputation: 1346
Same process only. But based operation of that process, it is run in user mode
and kernel mode
.
Modern processor architectures typically allow the CPU to operate in at least two
different modes: user mode
and kernel mode
(sometimes also referred to as supervisor
mode
).
Hardware instructions allow switching from one mode to the other. Correspondingly, areas of virtual memory can be marked as being part of user space
or kernel space
. When running in user mode
, the CPU can access only memory that is marked as being in user space
; attempts to access memory in kernel space
result in a hardware exception. When running in kernel mode
, the CPU can access both user and kernel memory space.
Certain operations can be performed only while the processor is operating in kernel mode
. Examples include executing the halt instruction to stop the system, accessing the memory-management hardware, and initiating device I/O operations. By taking advantage of this hardware design to place the operating system in kernel space, operating system implementers can ensure that user processes are not able to access the instructions and data structures of the kernel, or to perform operations that would adversely affect the operation of the system.
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
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.
Switching b/w kernel and user mode:
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://en.wikipedia.org/wiki/Direct_memory_access
http://en.wikipedia.org/wiki/Interrupt_request
Upvotes: 1