Search code examples
linux-kernelscheduled-tasksmulticore

On a multi-core machine which task_struct does the current macro return?


As far as I know current macro in kernel returns the task_struct of the running processes but what happen in case of multi-core machine? Does it return the task_struct of any random process running on any core?


Solution

  • task_struct first and foremost represents threads. There is no dedicated structure describing a process. The 'current' macro returns a pointer to task_struct of the thread in which context the kernel on given cpu is executing. Since a thread can be only executing on at most one cpu, there is no chances of confusion of any sort. If you have n cpus, all of them are executing stuff from different threads.