Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does there exist Kernel stack for each process ?

Does there exist a Kernel stack and a user-space stack for each user space process? If both stacks exist, there should be 2 stack pointers for each user space process right?

like image 839
nitin_cherian Avatar asked May 21 '11 17:05

nitin_cherian


People also ask

How many kernel stacks are there?

There is one "kernel stack" per CPU like ISR Stack and one "kernel stack" per Process. There is one "user stack" for each process, though each thread has its own stack, including both user and kernel threads. Why kernel stack is used?

Does each process have its own stack pointer?

This means that each process requires its own stack and stack pointer. If process A gets suspended, the (single) thread of execution will switch to another process B and start using B's stack pointer. In this way, a single thread can execute all processes in a design unit without corrupting their stacks.

Can a process have multiple kernel threads?

One process can have multiple threads, with each thread executing different code concurrently, while sharing data and synchronizing much more easily than cooperating processes. Threads require fewer system resources than processes, and can start more quickly.

What is the kernel stack of a process used for?

A separate kernel stack is needed for each process to save the state of the process. The state needs to be saved in case a task switch is performed, i.e. the current process is put to sleep, and some other process scheduled to run.


1 Answers

In Linux, each task (userspace or kernel thread) has a kernel stack of either 8kb or 4kb, depending on kernel configuration. There are indeed separate stack pointers, however, only one is present in the CPU at any given time; if userspace code is running, the kernel stack pointer to be used on exceptions or interrupts is specified by the task-state segment, and if kernel code is running, the user stack pointer is saved in the context structure located on the kernel stack.

like image 130
bdonlan Avatar answered Nov 04 '22 06:11

bdonlan