bash - 限制循环中进程的cpu限制

标签 bash loops ubuntu ffmpeg cpu-usage

我试图在多个文件的循环中执行 ffmpeg。我只想一次运行一个实例,并且只使用 50% 的 CPU。我一直在尝试 cpulimit 但它在循环中表现不佳。

for i in {1..9}; do cpulimit -l 50 -- ffmpeg <all the options>; done

这会同时生成所有 9 个作业,它们都属于 init,所以我必须打开 htop 来终止它们。

for i in {1..9}; do ffmpeg <all the options> & cpulimit -p $! -l 50; done

这挂了,ctrl+c 继续下一个循环迭代。这些实例只能被 SIGKILL 杀死。

最佳答案

使用队列是可行的方法。我使用的一个简单解决方案是 Task Spooler .您还可以限制 ffmpeg 使用 -threads 的核心数。这是给你的一些代码:

ts sh -c "ffmpeg -i INPUT.mp4 -threads 4 OUTPUT.mp4"
  • 您可以将最大并发任务数设置为 1:ts -S 1
  • 要查看当前队列,只需运行 ts

关于bash - 限制循环中进程的cpu限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48655688/

相关文章:

linux - BASH:如何对管道中的数字执行算术运算

bash - Shell exec 和管道

c# - 并行和异步方法

ubuntu - 如何启用 tcpreplay fragroute 引擎

linux - Jenkins : bash script ran with nohup is neither working nor writing anything to log

bash - “docker run”命令来评估容器内的bash $ variable

bash - bash 中的递归函数

java - 如何使用枚举中的字符串值作为输入来输出 Java 中该枚举项的其余数据?

java - 为什么我的 if else 语句不执行?

node.js - 当我启用 https 网站停止工作