Linux permanent background startup program nohup commmand &

Today, when deploying a service program on Linux, I usually want a program to run in the background, so I will often use & at the end of the program to let the program run automatically, so I execute it on the SSH client. /Server &, start successfully, close After the SSH client is launched, the running program is also terminated at the same time. How can we ensure that the program will continue to execute after launching the SSH client? Searching for information on the Internet, I found that the nohup command is needed. So use the following form of command:

nohup ./Server >/dev/null 2>&1 &

Parameter Description:

&: Refers to running in the background, but when the user exits (suspends), the command automatically exits;

nohup command: it means no hang up. , The command can be executed permanently, which has nothing to do with the user terminal;

1. Command line with &, even if the terminal is closed or the computer crashes, the program still runs (provided that you submit the program to the server); 

2. There are three commonly used streams in the operating system:
  0: standard input stream stdin
  1: standard output stream stdout
  2: standard error stream stderr

>/dev/null 2>&1, this means to redirect standard error (2) to standard output (1), and standard output is imported into the file /dev/null, so the result is that both standard error and standard output are imported /dev/null is inside. 

3. The role of the /dev/null file, this is a bottomless pit, anything can be directed here, but it cannot be opened.

Guess you like

Origin blog.csdn.net/Swallow_he/article/details/89551114