【问题标题】:How can I wait for the finish of execution of a command in Unix?如何在 Unix 中等待命令执行完成?
【发布时间】:2018-08-31 05:58:06
【问题描述】:

我在一个计算节点中有 25 个处理器。

我有一个主要的 python 脚本 A,它 a) 在循环中运行 3) 在每个循环中执行 20 tasks,它也分布在 25 个处理器中。

主要 Python 脚本 A

Lots of calculations

os.system("csh subtask.csh; wait")

Lots of calculations
Return to beginning of loop

其中,subtask.csh 属于这种类型:

./model -h 1 controlfile
./model -h 2 controlfile
./model -h 3 controlfile
./model -h 4 controlfile
./model -h 5 controlfile
... 
./model -h 20 controlfile

但是,这样,我的程序不会等待subtask.csh 完成。

我怎样才能让它等待?

【问题讨论】:

  • 它可能确实等待subtask.csh 完成(并且wait 命令不会做任何事情,因为没有什么可等待的)。如果subtask.csh./model 产生后台进程,调用者将看不到它们。
  • 谢谢,我刚刚发现作业没有跨处理器分配,而是按顺序进行......
  • 那么,有没有不同的等待方式,我知道这些子流程在做什么?
  • 我想知道他是在&(后台模式)下运行他的subtask.csh,还是在./model -h N control file level 上做同样的事情(实际上在这个级别,它应该是一个循环以及子任务内部.csh)并放入(附加模式)最后一个后台进程的PIDfoo & ; echo $! >> some_pids_file.txt,而不是使用wait,在subtask.csh(子shell)之外,他可以有一个循环来重新创建some_pids_file.txt 每次对于您拥有的所有 PID 或任何 ./model .. ... 进程,当此文件为 EMPTY 时,循环就会中断。我认为这是 maximusdooku 的最佳选择。
  • 我会在 subtask.csh 文件中为每个 ./model ... .. & 运行使用 &

标签: python bash shell unix csh


【解决方案1】:

你可以试试这个吗??

./model -h 1 controlfile &
./model -h 2 controlfile &
./model -h 3 controlfile &
./model -h 4 controlfile &
./model -h 5 controlfile &
wait

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 2018-04-27
    • 2019-12-31
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 2015-03-19
    相关资源
    最近更新 更多