开发者

How can I use nohup to run process as a background process in linux?

I use this command to run my work.

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

While, 1 is a number of process that I use to run this work. I have to change the number of process for each run. At each time it use long time to complete. Then I want to run it as b开发者_JAVA技巧ackground process.

How can I do it?

I tried:

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

But it doesn't work.


In general, I use nohup CMD & to run a nohup background process. However, when the command is in a form that nohup won't accept then I run it through bash -c "...".

For example:

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

stdout from the script gets written to script.out, while stderr and the output of time goes into time_n_err.out.

So, in your case:

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


You can write a script and then use nohup ./yourscript & to execute

For example:

vi yourscript

put

#!/bin/bash
script here

you may also need to change permission to run script on server

chmod u+rwx yourscript

finally

nohup ./yourscript &


  • Use screen: Start screen, start your script, press Ctrl+A, D. Reattach with screen -r.

  • Make a script that takes your "1" as a parameter, run nohup yourscript:

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


The modern and easy to use approach that allows managing multiple processes and has a nice terminal UI is hapless utility.

Install with pip install hapless (or python3 -m pip install hapless) and just run

$ hap run my-command  # e.g. hap run python my_long_running_script.py
$ hap status  # check all the launched processes

See docs for more info.

How can I use nohup to run process as a background process in linux?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜