Today, deploy the go program on Linux, execute chmod +x./xxx.exe on SSH client, start successfully, shut down SSH client, run the program also terminated, how to ensure that after the launch of SSH client program can always be executed? The nohup command is used to search for information on the Internet. Perfect solution:

nohup ./start-dishi.sh >output 2>&1 &
Copy the code

Purpose: To run commands without hanging up.

Syntax: nohup Command [Arg… [&]

Description: The nohup Command runs commands specified by the Command parameter and any associated Arg parameters, ignoring all SIGHUP signals. Run the program in the background using the nohup command after logout. To run the nohup command in the background, add & (the symbol for “and”) to the end of the command.

View processes that are running in the background

ps -ef | grep xxx
# XXX is the name of the thing to search for
Copy the code

There are three common flows in operating systems:

0: standard input stream stdin

1: standard output stream STdout

2: Standard error stream STderr

TXT (1>console. TXT);

When we use < console. TXT, it’s actually 0 < console. TXT.

Let’s get down to business:

nohup ./start-dishi.sh >output 2>&1 &

Explanation:

  1. The ampersand command line, which allows the program to run even when terminal is shut down or the computer crashes (if you submit the program to the server);

  2. 2 > &1

    This means that standard error (2) is redirected to standard output (1), which in turn is imported into output. The reason why you need to redirect standard error to standard output comes down to the fact that standard error does not have a buffer, whereas stdout does. This will cause the >output 2>output file output to be opened twice, and stdout and stderr will compete for overwrite, which is definitely not what we want.

Nohup./command. Sh >output 2>output

Finally, the /dev/null file is useful,

It’s a bottomless pit. Anything can be directed to it, but it can’t be opened. So generally large stdou and stderr can be directed here with stdout and stderr when you don’t care >./ command-sh >/dev/null 2>&1