Linux process “scheduling”

kernellinux

I've seen it written many times that the Linux scheduler schedules processes. I'm teaching a course on multithreaded programming, and would like to get my terminology straight. I have one thing I would like to say about it (written below), hoping someone can help me clear out the most egregious errors:

It's not the process that the scheduler schedules, it's the thread
associated to that process. The process is simply a bunch of memory
mapping segments, and thus static. We can see this clearly when we
pthread_create() or even clone() (mostly, but not exactly, the
same), whereby one process has several threads, and it is those that
are scheduled (otherwise you would only schedule the process thread
(the PID=TID one), rather than any other. I assume the ambiguity is
due to the fact that all processes have at least one thread of
execution.

Is this the correct (although simplified) picture?

Best Answer

Try something like this:


All processes start with just one thread, and can create more, using pthread_create for example. (All of a process's threads created this way share the same address space.) The kernel's scheduler works on these threads, regardless of whether they're a process's "main"/initial thread or additional ones - there's essentially no difference between them from scheduler's point of view.

Linux initially didn't have threads at all, only processes. So the part of the OS that schedules "CPU work" is generally called the process scheduler, for historical reasons. (This isn't Linux-specific, same thing for most (all?) Unix-type systems. Thread scheduler is simply not the usual vocabulary used.)


I wouldn't even mention clone (let alone vfork) at that point, unless you've already explained the whole namespaces business.

Related Question