我有一个 python 程序,我通过命令行(Mac OSX)运行它:
python -W ignore Experiment.py --iterations 10
该文件Experiment.py应使用不同的值运行多次--iterations。我一次又一次地手动执行此操作,因此当一次运行完成后,我会使用不同的 运行第二次运行--iterations,依此类推。但是,我不能总是靠近我的笔记本电脑来运行所有这些程序,所以我想知道是否有一种方法shell script可以一起声明所有运行,然后 shell 脚本一个接一个地执行它们(不是并行的,只是按顺序执行,就像我我会自己做吗)?就像是:
python -W ignore Experiment.py --iterations 10
python -W ignore Experiment.py --iterations 100
python -W ignore Experiment.py --iterations 1000
python -W ignore Experiment.py --iterations 10000
python -W ignore Experiment.py --iterations 100000
Run Code Online (Sandbox Code Playgroud)
编辑:
如果我有多个参数怎么办--X --Y --Z?
我想将处理能力限制在我的机器中只有一个核心,所以我发现taskset可以帮助设置一个核心,比如核心 0,如下(由这个答案提供):
taskset -c 0 -p 45678
Run Code Online (Sandbox Code Playgroud)
问题是,当我的程序还没有运行时,我如何在这里确定 process_id pid?在这种情况下,我们是否只是设置了一个由 Linux 获取的任意进程 ID 45678?如果是这样,是否可以在 shell 脚本中执行以下操作:
#!/bin/sh
# Set the processing unit
taskset -c 0 -p 45678
# run python script
python main.py
Run Code Online (Sandbox Code Playgroud)