How Linux scheduler identifies which process is from kernel space and which process is from user space? Suppose I installed an application in the Linux. I started the application. Simultaneously there are other kernel space processes into the ready queue. Now how can the Linux scheduler identify that the which queued process is from kernel space and which one is from user space..?
1 Answers
I'm not expert but I started reading the kernel source 2 days ago and when it comes to processes you can almost always find all the data that you need from one struct. The struct is called task_struct and is defined in include/linux/sched.h file of the kernel source tree.
You can look it up here: https://github.com/torvalds/linux/blob/master/include/linux/sched.h#L1274
From what I understand, although I might be wrong, the kernel has no idea if the process/thread that it schedules is a user process or a kernel thread.
According to Robert Love's book on the Linux Kernel, the main difference from the system's point of view between a user process and a kernel thread is that kernel threads do not have an address space. Their mm pointer in their task_struct is NULL.
So from the above, I assume that if you really want to know whether a task is a kernel thread you could check this structure.