linux - 限制允许使用进程树的 CPU 百分比?

标签 linux unix

我能否限制正在运行的进程及其所有当前和 future 子进程可以使用的 CPU 百分比?我听说过 cpulimit 工具,但它似乎忽略了子进程。

编辑 所以,the answer我发现需要 cpulimit 持续运行,直到我们希望限制保持有效,因为它通过主动发送挂起然后继续信号到进程来进行限制。是否有其他方法可以实现这种限制效果,也许不需要在后台运行这样的辅助进程?

最佳答案

是的!

就在我写这个问题的时候,发现我正在尝试旧版本的cpulimit

new version也支持限制子进程。

$ cpulimit -h
Usage: cpulimit [OPTIONS...] TARGET
   OPTIONS
      -l, --limit=N          percentage of cpu allowed from 0 to 400 (required)
      -v, --verbose          show control statistics
      -z, --lazy             exit if there is no target process, or if it dies
      -i, --include-children limit also the children processes
      -h, --help             display this help and exit
   TARGET must be exactly one of these:
      -p, --pid=N            pid of the process (implies -z)
      -e, --exe=FILE         name of the executable program file or path name
      COMMAND [ARGS]         run this command and limit it (implies -z)

Report bugs to <marlonx80@hotmail.com>.

关于linux - 限制允许使用进程树的 CPU 百分比?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31623697/

相关文章:

c++ - int的C赋值

linux - 重定向到/dev/null AND 文件?

linux - 更新文件名最后一个字符的 Shell 脚本

php - 相当于 PHP 的 preg_replace() 的 Shell

c++ - linux会不会阻止栈和堆互相生长?

python - 如何让 venv 安装 python3.6 二进制文件?

linux - 需要一个简单的 Linux C++ IDE (Android NDK)

unix - 给定进程名称如何获取pid

linux - 如何将文本插入到conf文件中?

php - 如何使用邮件功能使用 php 表单脚本将邮件从我的网站电子邮件发送到 gmail?