2011-03-02 96 views
35

我使用这个命令来运行我的工作。如何使用nohup在Linux中作为后台进程运行进程?

(time bash executeScript 1 input fileOutput $> scrOutput) &> timeUse.txt 

虽然,1是我用来运行此工作的一些进程。我必须更改每次运行的进程数。在每一次它使用很长时间来完成。然后我想运行它作为后台进程。

我该怎么办?

我想:

nohup ((time bash executeScript 1 input fileOutput $> scrOutput) &> timeUse.txt) 

但它不工作。

回答

5
  • 使用屏幕:启动screen,开始你的脚本,请按Ctrl键+一个d。与screen -r重新连接。

  • 制作一个脚本,需要你的 “1” 作为参数,运行nohup yourscript

    #!/bin/bash 
    (time bash executeScript $1 input fileOutput $> scrOutput) &> timeUse.txt 
    
48

一般情况下,我用nohup CMD &运行的nohup后台进程。但是,如果命令的格式为nohup不会接受,那么我通过bash -c "..."运行它。

例如:从脚本

nohup bash -c "(time ./script arg1 arg2 > script.out) &> time_n_err.out" & 

标准输出被写入script.out,而标准错误和time输出进入time_n_err.out

所以,你的情况:

nohup bash -c "(time bash executeScript 1 input fileOutput > scrOutput) &> timeUse.txt" & 
19

您可以编写一个脚本,然后使用nohup ./yourscript &执行

例如:

vi yourscript 

#!/bin/bash 
script here 

您还可能需要更改权限,在服务器上运行脚本

chmod u+rwx yourscript 

终于

nohup ./yourscript &