【问题标题】:How can I use the "nice" command in combination with the "parallel" command to set the priority level of multiple processes in Linux?在 Linux 中,如何结合使用 \"nice\" 命令和 \"parallel\" 命令来设置多个进程的优先级?
【发布时间】:2023-01-16 21:51:06
【问题描述】:
在Linux中如何使用“nice”命令结合“parallel”命令来设置多个进程的优先级?
我尝试了以下方法:
nice -n 3 parallel command ::: arg1 arg2 arg3 arg4
parallel --nice 19 command ::: arg1 arg2 arg3 arg4
但它似乎不起作用:代码运行,但友好级别似乎并未应用于并行运行的进程。
关于如何正确使用并行的 nice 命令有什么建议吗?
【问题讨论】:
标签:
parallel-processing
gnu
nice
【解决方案1】:
“nice”命令可用于在 Linux 中设置进程的优先级。 “并行”命令可用于并行执行多个命令。要结合使用“nice”和“parallel”来设置多个进程的优先级,可以使用以下命令语法:
nice -n <priority level> parallel <command> ::: <arguments>
在哪里:
<priority level> 是介于 -20(最高优先级)和 19(最低优先级)之间的整数值
<command>是你要执行的命令
<arguments> 是命令的参数列表,以空格分隔
例如,要运行带有参数“arg1”和“arg2”的命令“command1”的 2 个进程,每个进程的优先级均为 10,则命令为:
nice -n 10 parallel command1 ::: arg1 arg2
这使用 nice 命令并行运行命令“command1 arg1”和“command1 arg2”,优先级为 10。
注意 nice 命令只会影响进程的 CPU 调度优先级,不会影响 I/O 或内存优先级。此外,您设置的优先级可能会受到用户权限的限制。
【解决方案2】:
更新:
您可以使用:
parallel --jobs 5 command ::: arg1
我很确定以上评论来自 Chat GPT。 :/