Centos command describes the background to run the program offline

nohup, &,>, / dev / null, 2> & 1 Introduction

& Background process

& Command parameters: command and later added to the original parameters & Space, at this time when there is the log will still be output to the screen, but the process will run in the background, we can still perform other commands in the foreground. After just off the end of the process or putty will end, and we do not want to see those logs in the foreground.


nohup always run

nohup command parameters: nohup position in front of the command, even if you close putty end of the process will continue to execute its logs are not output to the front, but in nohup.out record files in the current directory. & No default is performed in the foreground, the foreground is occupied can not enter other commands, and ctrl + c will still end the current foreground program.


nohup combination &

& nohup command parameters: When using a combination of both, the process will always run in the background, in the foreground close putty terminal or ctrl + c will not shut down, log output to nohup.out.

命令示例:$ nohup 命令 参数 &  

> Output file

If we do not want to export logs to nohup.out, but want to output to test.out

示例:$ nohup 命令 参数 >test.out &

/ Dev / null black hole equipment

Usually some java frameworks like spring will configure logging, we do not need to log linux, but a long time nohup.out files become very large, so we log all thrown in linux / dev / null, the equivalent to the trash, will not produce a log linux.

示例:$ nohup 命令 参数 >/dev/null &

2> & 1 error output

There is a very popular command format is:

$ nohup 命令 参数 >/dev/null 2>&1 &

More than a 2> is the error information output 1.2 & than the above, a standard message is output. > / Dev / null into a black hole is, 2> & 1 is a 2 into 1, eventually into a black hole. We have to figure out, not the exception log 2 program is running, but linux system error, such as nohup command, this command we make a mistake, missed one letter, the system will give prompt us immediately. And you add 2> & 1 later, this error message to enter a black hole, you can only look on in despair bewildered.


Original: https://blog.csdn.net/wangb_java/article/details/80952865

Guess you like

Origin blog.csdn.net/DPnice/article/details/84341388