暂停非必要的 CPU 进程

发布于 2024-12-28 04:02:52 字数 149 浏览 2 评论 0原文

是否可以命令 CPU 暂停所有非必要的进程,直到我的程序完成处理?目标是减少竞争 CPU 处理时间的进程数量,我最终期望程序的挂钟运行时间得到改善。

所以我想开始运行我的程序,命令CPU暂停除我的程序之外的非必要进程,并且当我的程序终止时CPU可以恢复之前暂停的进程。

Is it possible to command the CPU to pause all non-essential processes until my program has finished processing? The goal being to reduce the amount of processes competing for CPU processing time, and I am ultimately expecting an improvement in wall-clock running time of my program.

So I want to start my program running, command the CPU to pause non-essential processes except for my program, and when my program terminates then the CPU can resume the previously paused processes.

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

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

发布评论

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

评论(1

冷︶言冷语的世界 2025-01-04 04:02:52

在 Linux 上,明显的初始策略是使用 renice 提高进程的优先级。 nice 值越低,优先级越高,最大优先级为-20。

(例如,我创建一个长时间运行的进程)

sleep 100000 &

作为该进程的 root grep ;

ps -ef | grep sleep

500       **4323**  2995  0 18:44 pts/1    00:00:00 sleep 100000
500       4371  2995  0 18:45 pts/1    00:00:00 grep --color=auto sleep

将进程调整为非常高的优先级;

renice -20 4323

您还可以发送 SIGSTOP 和 SIGCONT 信号来停止和继续特定进程,如下所示;

skill -STOP -p <processid>
skill -CONT -p <processid>

不幸的是,非必要流程的构成取决于您自己的定义。您可以通过检查进程列表来停止所有非 root 进程,并使用以下命令暂时停止所有特定用户的进程;

skill -STOP -u <userid>
skill -CONT -u <userid>

显然要小心停止进程,例如生成 sudo root 会话的 shell。

On linux, The obvious initial tactic is to increase the priority of your process using renice. The lower the nice value, the higher the priority, with a maximum priority of -20.

(here i create a long running process for example)

sleep 100000 &

as root grep for the process;

ps -ef | grep sleep

500       **4323**  2995  0 18:44 pts/1    00:00:00 sleep 100000
500       4371  2995  0 18:45 pts/1    00:00:00 grep --color=auto sleep

renice the process to a very high priority;

renice -20 4323

You can also send the SIGSTOP and SIGCONT signals to Stop and Continue particular processes like so;

skill -STOP -p <processid>
skill -CONT -p <processid>

Unfortunately, what constitutes non-essential processes is dependent on your own definition. You can stop all non-root processes by examining the process list, and using the following command to stop all of a particular user's processes temporarily;

skill -STOP -u <userid>
skill -CONT -u <userid>

Obviously beware of stopping processes such as the shell that spawned your sudo root session.

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