Linux系统上的进程的友善度和优先级

发布于 2024-11-02 04:28:54 字数 129 浏览 1 评论 0原文

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

有没有可以设置优先级的命令? (或者我对友善和优先级感到困惑吗?)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-11-09 04:28:54

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 时间可用 - 如今它们速度很快。不幸的是,HDD 在随机 I/O 上仍然相对较慢,因此即使是一个好的进程也可以生成足够的 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.

The priority is taken into account when there are more processes running than CPU cores available: Highest priority wins. But as the winning process loses 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文