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

查看:30
本文介绍了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?

推荐答案

Linux 内核调度器 实际上是在调度任务,这些任务要么是线程,要么是(单线程)进程.

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

所以task(内核中的一个task_struct),在调度器的上下文中,是被调度的东西,可以是一些内核线程,如kworkerkswapd,多线程进程的一些用户线程(如firefoxcode>),或单线程进程的单线程(如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.

进程 是一个非空的有限集(有时是单例)线程 共享相同的虚拟地址空间(以及其他诸如 文件描述符工作目录等......).另请参阅 credentials(7)capabilities(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 特定的 clone 系统调用(也可用于在 Linux 上创建进程).pthread_create 函数可能是在 clone 之上构建的(在 Linux 上)NPTLGnu Libc(在 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天全站免登陆