Take the 2-minute tour ×

I looked at a lot if online thread/tutorials regarding how process address space is divided into process/kernel

Ex: i have some Helloworld program in that i have call as printf(in turn it makes write system call to enter into kernel space)

My doubt how Helloworld program stack used by kernel. Can you tell me how whole execution goes on...

./helloworld -> printf() -> write system call -> display driver -> return from write -> back to helloworld

Thanks, Amarender

share|improve this question

2 Answers 2

The detailed answer to this question depends on the specific kernel and architecture. However, the general answer is that when userspace wants to call into the kernel, it executes a trap instruction, that causes the CPU to change privilege level and start executing kernel code. As part of the privilege level change, the CPU will also switch to a kernel stack. When the kernel is done, it will execute a return-from-trap sequence that restores the userspace stack and resumes execution where it left off.

share|improve this answer

In a nutshell: When the write system call is made, int $80 trap is generated. The handler saves the current process registers on the Kernel stack (present in the kernel address space). Then CPL in segment registers are changed to enable the use of kernel page tables. Then the kernel looks up its table of system calls and finds the appropriate address of the desired routine. The execution then jumps to the routine which in turn may call the device driver code. After doing its work, the kernel returns to user mode by restoring the register content and CPL in the segment registers.

share|improve this answer

Your Answer


