我如何使用nohup将进程作为linux中的后台进程运行?

时间:2011-03-02 08:17:11

标签: linux

我使用此命令来运行我的工作。

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

虽然,1是我用来运行这项工作的一些过程。我必须改变每次运行的进程数。每次使用很长时间才能完成。然后我想将它作为后台进程运行。

我该怎么做?

我试过了:

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

但它不起作用。

3 个答案:

答案 0 :(得分:59)

通常,我使用nohup CMD &来运行nohup后台进程。但是,当命令采用nohup不接受的格式时,我会通过bash -c "..."运行。

例如:

nohup bash -c "(time ./script arg1 arg2 > script.out) &> time_n_err.out" &
来自脚本的

stdout被写入script.out,而stderr和time的输出进入time_n_err.out

所以,在你的情况下:

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

答案 1 :(得分:29)

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

例如:

vi yourscript

#!/bin/bash
script here

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

chmod u+rwx yourscript

最后

nohup ./yourscript &

答案 2 :(得分:5)

  • 使用屏幕:启动screen,启动脚本,按 Ctrl + A D 。重新附加screen -r

  • 创建一个以“1”为参数的脚本,运行nohup yourscript

    #!/bin/bash
    (time bash executeScript $1 input fileOutput $> scrOutput) &> timeUse.txt
    
相关问题