2011-03-02 98 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 &