Linux如何处理线程和进程调度 [英] How Linux handles threads and process scheduling

查看:301
本文介绍了Linux如何处理线程和进程调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解Linux如何处理进程调度和线程调度.我了解到Linux可以调度进程和线程.

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

Linux是否有线程调度程序和进程调度程序?如果是,他们如何合作?

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

推荐答案

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

因此,在调度程序的上下文中,任务(内核内部的task_struct)是正在调度的事物,并且可以是某些内核线程(例如kworkerkswapd),多线程进程(例如firefox)的某些 user线程,或单线程进程的单线程 em>(如bash),由该单线程进程标识.

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.

过程是一个非空的有限集(有时是一个单例)共享相同线程 .org/wiki/Virtual_address_space"rel =" noreferrer>虚拟地址空间(以及文件描述符工作目录等).另请参见凭据(7)

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....

Linux上的线程是内核线程(在由内核管理的意义上,内核也创建自己的线程),由Linux特定的 pthread_create 函数可能是在Linux上 NPTL musl-libc .

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.

这篇关于Linux如何处理线程和进程调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆