What does a Process look like in Linux Kernel source code?
While preparing for my next video, I got curious about how the process is represented in the Linux Kernel source code, and this is what I found.
The process is represented as task_struct, and I have attached a trimmed snippet of the struct definition. You could actually see the things we studied in the OS course in there, like process ID, a pointer to the stack, scheduling statistics, thread references, mutexes, etc.
One interesting attribute I found in the struct was usage, and it interestingly had type refcount_t. Scrolling through the documentation, I found that this is an important attribute that helps in scheduling decisions.
The usage attribute holds the number of tasks that depend on this one. The Linux Scheduler leverages usage to prioritize tasks with higher usage counts (more dependencies) to ensure the timely completion of operations that rely on them.
This is why I admire open source, because when in doubt or when curious, you have the source to explore.
I have linked the source code in the comments below.
btw, enrollments open for sys design cohort - arpitbhayani.me/course