When it comes to kernel space and userspace understanding, this example would definitely help.
In Bengaluru, we have self-service hotels where we need to pay the money at bill counter for our choice and get the coupon . Using coupon , we can order food with the set of guys who are waiting to serve.
In this above pic, we can see 2 different area where one guy is asking for service and other area couple of black dressed guys receiving order.
Its the same way how user space and kernel space program communicates. Lets take the analogy to technical.
Kernel Space: Kernel space is region where it has access to actual kitchen. In this region dishes are made and served according to customer needs. The guys who work in this region are good at preparing dishes.Drivers are those guys who link between the kitchen and customers.
Kernel space region has complete access to hardware. Examples include handling raw memory, interacting with disk , keyboard,mouse etc..
Userspace : It's the region of memory where user space programs work.If the user-space wants to interact with hardware, it places a request for kernel which executes in kernel space. The request is usually done through system calls.The switch between user space and kernel space is called context switch. Here it need not that all instructions need a switch to kernel space for executing instructions. Example add instruction doesnt need kernel privilage whereas allocating memory needs it.
Now couple of FAQ's?
Is the memory physically divided or virtual?
Best answer is here .
Is does linux really needs the distinction?
Linux is more secure and this is also one of the reason. User is not given direct access to many things. user placed requests are handled carefully and are serviced.
Practical perspective:
Lets get into code and see what's userspace and kernel space.
How system call works?
No comments:
Post a Comment