Linux内核中使用的三个优先级之间有什么区别? [英] what is the difference among three priorities used in Linux kernel?

查看:255
本文介绍了Linux内核中使用的三个优先级之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Linux内核的新手,现在我正在研究Linux内核中的进程调度. Linux中有三种优先级:

I am new to Linux kernel and right now i am studying about Process Scheduling in Linux kernel . There are three types of priorities in Linux :

  1. 静态优先级
  2. 动态优先级
  3. 实时优先

现在我了解的是:

  • 静态优先级和动态优先级仅针对常规流程定义,它们的取值范围只能从100到139.
  • 静态优先级用于确定进程的基本时间片
  • 动态优先级用于选择下一个要执行的进程.

  • Static priority and Dynamic priority are defined only for Conventional processes and they can take value from 100 to 139 only.
  • Static priority is used to determine base time slice of a process
  • Dynamic priority is used to select a process to be executed next.

实时优先级已定义仅适用于实时进程,其值的范围可以从0到99

Real time priorities are defined only for Real time processes and it's value can range from 0 to 99

现在我的问题是:

  1. 如果我错了,请纠正我,并请告诉我为什么我们使用 Linux中的三种优先级,有什么不同 这些优先事项之中?
  2. 在优先级的基础上(例如,优先级在100到139之间),流程是区分为实时还是常规? 则流程为常规流程,否则为实时流程 程序吗?
  3. 在Linux中如何更改优先级,我是说,我们知道在整个执行过程中进程的优先级不会保持恒定吗?
  1. Correct me if i am wrong and please also tell me why we are using three types of priorities in Linux and what are the differences among these priorities?
  2. Are the processes are differentiated as Real time or Conventional on the basis of priorities that is if priority is between 100 to 139 then processes are Conventional processes otherwise Real time processes?
  3. How the priorities are changed in Linux , i mean , we know that priority of a process does not remain constant through out the execution ?

推荐答案

免责声明:对于在Linux中进行调度,以下是正确的(我不确定Windows或其他OS).线程和进程在这里可以互换使用,尽管它们之间是有区别的.

Disclaimer: Following is true for scheduling in linux (I am not sure about windows or other OS). Thread and process has been used interchangeably here, althogh there is a difference in between them.

优先级和差异

1.静态优先级:这些是在创建新线程时设置的默认优先级(传统进程或非实时进程,即不使用实时调度时的值0).您可以使用以下方法更改它们:

1.Static priority: These are the default priorities (value 0 for conventional processes aka non-real time processes ie when real time scheduling is not used) set while creating a new thread. You can change them using:

`pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param);`

其中sched_pa​​ram包含优先级:

where, sched_param contains the priority:

struct sched_param 
{
    int sched_priority;     /* Scheduling priority */
};

2动态优先级:当线程由于总是调度更高优先级的线程而开始出现饥饿时,就需要使用

2 Dynamic priority: When threads start to starve because higher priority threads being scheduled all the time, there becomes a need to raise the priority of such a thread using various mechanisms. This raised/lowered (yes, this happens too) priority is known as the dynamic priority because it keeps on changing. In Linux, even the fat kid gets to play.

3.实时优先级:仅当在一种实时策略(SCHED_FIFO,SCHED_RR)下调度线程(进程)并且其sched_priority值在1范围内时,此选项才会显示(低)至99(高).与非实时过程的静态/动态优先级相比,这是最高的.

3.Real time priority: This comes into picture only when threads (processes) are scheduled under one of the real-time policies (SCHED_FIFO, SCHED_RR) and have a sched_priority value in the range 1 (low) to 99 (high). This is the highest in comparison to the static/dynamic priorities of non real time processes.

更多信息: http://man7.org/linux/man-pages/man3/pthread_getschedparam.3.html

现在,向您提出问题:

如果我错了,请纠正我,并请告诉我为什么我们在Linux中使用三种类型的优先级,以及之间的区别是什么? 这些优先事项?

Correct me if i am wrong and please also tell me why we are using three types of priorities in Linux and what are the differences among these priorities?

因此,对于非实时调度策略,每个进程都有一些静态优先级,较高的优先级将使线程启动,而以后为了避免任何不公平的情况,将优先级提高/降低,这将成为动态优先级.

So, for non-real time scheduling policies, every process has some static priorities, a higher priority gives the thread a kick-start, and later to avoid any injustice, the priority is boosted/lowered which becomes the dynamic priority.

在优先级的基础上(例如,优先级在100到139之间),流程是区分为实时还是常规? 则流程为常规流程,否则为实时流程 程序吗?

Are the processes are differentiated as Real time or Conventional on the basis of priorities that is if priority is between 100 to 139 then processes are Conventional processes otherwise Real time processes?

并非如此,这取决于适当的调度机制.

Not really, it depends upon the scheduling mechanism in place.

在Linux中如何更改优先级,我的意思是,我们知道在整个过程中,进程的优先级不会保持恒定. 执行?

How the priorities are changed in Linux , i mean , we know that priority of a process does not remain constant through out the execution ?

那是动态的体现.在给定的链接中了解很好的价值".

That's when the dynamicness comes into picture. Read about the "nice value" in the given links.

这篇关于Linux内核中使用的三个优先级之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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