linux是否调度进程或线程? [英] Does linux schedule a process or a thread?

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

问题描述

在阅读这个 SO问题后,我有些疑问.请帮助理解.

After reading this SO question I got a few doubts. Please help in understanding.

计划涉及确定何时运行流程以及运行时间的时间.

Scheduling involves deciding when to run a process and for what quantum of time.

  1. Linux内核是否调度线程或进程?由于内核中的进程和线程没有区别,因此调度程序如何处理它们?

  1. Does linux kernel schedule a thread or a process? As process and thread are not differentiated inside kernel how a scheduler treats them?

如何确定每个线程的量子量? 一种.如果为一个进程确定了一个时间量(例如100us),是该进程的所有线程之间共享的时间吗?或者 b.每个线程的数量由调度程序决定吗?

How quantum for each thread is decided? a. If a quantum of time (say 100us) is decided for a process is that getting shared between all the threads of the process? or b. A quantum for each thread is decided by the scheduler?

注意:问题1和问题2是相关的,可能看起来相同,但只是想弄清楚事情的进展方式,在这里都将它们都贴了.

Note: Questions 1 and 2 are related and may look the same but just wanted to be clear on how things are working posted them both here.

推荐答案

Linux调度程序(至少在最新的Linux内核上,例如3.0)正在调度可调度任务或只是 tasks .

The Linux scheduler (on recent Linux kernels, e.g. 3.0 at least) is scheduling schedulable tasks or simply tasks.

任务可能是:

  • 单线程进程(例如,由fork创建,没有任何线程库)
  • 多线程进程中的任何线程(包括其主线程),尤其是Posix线程(pthreads)
  • 内核任务,这些任务在内核内部启动并停留在内核领域(例如kworkernfsiodkjournaldkauditdkswapd等,等等)
  • a single-threaded process (e.g. created by fork without any thread library)
  • any thread inside a multi-threaded process (including its main thread), in particular Posix threads (pthreads)
  • kernel tasks, which are started internally in the kernel and stay in kernel land (e.g. kworker, nfsiod, kjournald , kauditd, kswapd etc etc...)

换句话说,多线程进程内部的线程的调度方式类似于非线程-i.单线程进程.

In other words, threads inside multi-threaded processes are scheduled like non-threaded -i.e. single threaded- processes.

clone(2)底层系统调用用户级可调度任务(可用于创建fork -ed进程或用于实现线程库,例如 pthread ).除非您是低级线程库实现者,否则您不希望直接使用clone.

The low-level clone(2) syscall creates user-land schedulable tasks (and can be used both for creating fork-ed process or for implementation of thread libraries, like pthread). Unless you are a low-level thread library implementor, you don't want to use clone directly.

AFAIK,对于多线程进程,内核(几乎)不是在调度进程,而是内部的每个线程(包括主线程).

AFAIK, for multi-threaded processes, the kernel is (almost) not scheduling the process, but each individual thread inside (including the main thread).

实际上,在调度中有一些线程组概念和 affinity ,但我不太了解他们

Actually, there is some notion of thread groups and affinity in the scheduling, but I don't know them well

如今,处理器通常具有多个内核,并且每个内核都正在运行一个任务(在给定的瞬间),因此您确实有多个并行运行的任务.

These days, processors have generally more than one core, and each core is running a task (at some given instant) so you do have several tasks running in parallel.

CPU量子时间分配给任务,而不是进程

CPU quantum times are given to tasks, not to processes

这篇关于linux是否调度进程或线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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