I am currently studying on Linux operating system.

My problem is with threads inside Linux.

I know that every process has it own PCB of size 1KB inside the kernel and an additional 7KB stack space inside the kernel. In the PCB there are all the relevant data fields of this process i.e. FDT, Signal handlers Table...

Now, When I am doing fork(), I am creating a new PCB and kernel stack for the new process and copying to it everything that is in the father's PCB (that should be copied).

My problem with understanding starts when I am creating threads, I know that each thread has it own TCB and it's own kernel stack and everything else is shared between them.

My questions are:

  1. When and how is this TCB and thread stack created?

  2. Where is this TCB located? Is it also a part of the 1KB process PCB like the threads stacks are part of the process kernel stack?

  3. How is the clone() system call included when you creating thread? I know that it should receive entry function, user stack of the new thread, flags and additional arguments, therefore, it should be invoked after the TCB is already created.

  4. When the scheduler gets the next task (task_struct == next task PCB) to run from the run queue how does he know which thread should be running from this process?

  5. And finally, are the run queues can be shared between the processors, meaning can every processor access to all of the run queues or they are unique per processor? And if so, how is the parallel method is working within many processors system?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.