Working with the task structure via ‘current’
Here, we will write a simple kernel module to show a few members of the task structure. Further, I want you to think about this: who exactly is running the code of this (or any) kernel module’s (or the kernel’s) init and cleanup code paths? From what we’ve learned, it’s not the kernel; as stated before, there’s no grand overall “kernel” process as such… Then, who’s running it?
The answer should be clear in a monolithic kernel such as the Linux OS: when a user space process (or thread) issues a system call, it switches to kernel mode and runs kernel (or module) code in process context. So, yes, it will be a process (or thread). Which one? The code we write will reveal the process context that our module’s init and cleanup code paths run in. (We discuss this very point in more detail in the upcoming Seeing that the Linux OS is monolithic section.) To...