whitefox
whitefox

Reputation: 965

How Linux handles threads and process scheduling

I'm trying to understand how Linux handles process scheduling and thread scheduling. I read that Linux can schedule both processes and threads.

Does Linux have a thread scheduler AND a process scheduler? If yes, how do they cooperate?

Upvotes: 34

Views: 46244

Answers (3)

The Linux kernel scheduler is actually scheduling tasks, and these are either threads or (single-threaded) processes.

So a task (a task_struct inside the kernel), in the context of the scheduler, is the thing being scheduled, and can be some kernel thread like kworker or kswapd, some user thread of a multi-threaded process (like firefox), or the single-thread of a single-threaded process (like bash), identified with that single-threaded process.

A process is a non-empty finite set (sometimes a singleton) of threads sharing the same virtual address space (and other things like file descriptors, working directory, etc etc...). See also credentials(7), capabilities(7) etc....

Threads on Linux are kernel threads (in the sense of being managed by the kernel, which also creates its own threads), created by the Linux specific clone syscall (which can also be used to create processes on Linux). The pthread_create function is probably built (on Linux) above clone inside NPTL and Gnu Libc (which integrated NPTL on Linux) and musl-libc.

Upvotes: 51

kiran
kiran

Reputation: 1

Under LINUX there is no concept of threads,to make LINUX POSIX complaint thread is nothing but another process.when you try to get a process id it would display the leader process id under any thread. For more details try to refer this book "Understanding LINUX kernel".Hope

Upvotes: -6

nurio
nurio

Reputation: 553

Kernel threads under Linux are implemented as processes that share resources. The scheduler does not differentiate between a thread and a process

See here for more information: http://www.linuxquestions.org/linux/articles/Technical/Linux_Kernel_Thread

Upvotes: 26

Related Questions