Linux 系统上的 niceness 和优先进程 [英] Niceness and priority processes on Linux system

查看:35
本文介绍了Linux 系统上的 niceness 和优先进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种通过命令行修改进程优先级的方法.我发现内置 (bash) nice 和命令 renice 允许修改进程的好坏,但不是内核计算的实际优先级.

I am looking for a way to modify a process' priority through command line. I found the builtin (bash) nice and the command renice which allow to modify the niceness of the process, but not the actual priority which is calculated by the kernel.

是否有允许设置优先级的命令?(或者我在友善和优先之间感到困惑?)

Is there a command which allows to set the priority? (Or am I confused between niceness and priority?)

推荐答案

linux中进程的优先级是动态的:运行时间越长,优先级越低.进程在实际使用 CPU 时运行 - 典型 Linux 机器上的大多数进程只是等待 I/O,因此不计为 正在运行.

The priority of a process in linux is dynamic: The longer it runs, the lower its priority will be. A process runs when its actually using the CPU - most processes on a typical Linux box just wait for I/O and thus do not count as running.

当运行的进程数超过可用的 CPU 内核数时会考虑优先级:最高优先级获胜.但是随着时间的推移,获胜的进程会失去其优先权,其他进程将在某个时候接管 CPU.

The priority is taken into account when there are more processes running than CPU cores available: Highest priority wins. But as the winning process looses its proirity over time, other processes will take over the CPU at some point.

nicerenice 将从优先级中添加/删除一些点".具有较高 nice 值的进程将获得较少的 CPU 时间.Root 也可以设置一个负的 nice 值——进程获得更多的 CPU 时间.

nice and renice will add/remove some "points" from priority. A process which has a higher nice value will get lesser CPU time. Root can also set a negative nice value - the process gets more CPU time.

示例:系统中有两个进程(1 和 2)计算停机问题和一个 CPU 内核.默认值为 nice 0,因此两个进程各自获得大约一半的 CPU 时间.现在让 renice 进程 1 的值为 10.结果:进程 2 获得的 CPU 时间比进程 1 高得多.

Example: There are two processes (1 and 2) calculating the halting problem and one CPU core in the system. Default is nice 0, so both processes get about half of the CPU time each. Now lets renice process 1 to value 10. Result: Process 2 gets a significant higher amount of cpu time as process 1.

注意:在现代台式机中,有大量可用的 CPU 时间 - 现在它们速度很快.不幸的是,HDD 在随机 I/O 上仍然相对较慢,因此即使是 nice 进程也可以产生足够的 I/O 流量来显着降低系统速度.

Note: In modern desktops there is plenty CPU time available - they are fast these days. Unfortunately HDDs are still relativeley slow on random I/O, so even a nice process can generate enough I/O traffic to significantly slow down a system.

这篇关于Linux 系统上的 niceness 和优先进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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