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

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

问题描述

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

是否有允许设置优先级的命令?(还是我混淆了友好和优先级?)

解决方案

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

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

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

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

注意:在现代台式机中,有足够的 CPU 时间可用 - 现在它们速度很快.不幸的是,硬盘驱动器在随机 I/O 上仍然相对较慢,因此即使一个不错的进程也会产生足够的 I/O 流量,从而显着降低系统速度.

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?)

解决方案

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.

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.

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.

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.

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和priority进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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