What is the structure used for saving thread state like PC, SP and registers during thread context switch in linux? The equivalent of TCB in freebsd. If possible please point to the source file here.
Note that PCB itself is not enough, as we have PC, SP etc. per thread not per process.
It’s actually
task_struct. In Linux, a task can be a thread, a process, or something in between. A thread is just the name you give to a task that shares most things (VMA’s, file descriptors, etc…) with other tasks.This is much in line with the idea that a thread is just a particular kind of process, and can be handled via the same functions, etc… Plan 9’s
rfork()and Linux’sclone()allow to create a process with a customizable level of sharing, so you end up using the same machinery to create processes and threads.