If I do
nohup cmd1 | cmd2 &
is that the same as
nohup "cmd1 | cmd2" &
?
I would like that I nohup
everything, as cmd1
will listen on port 8023.
Since there isn't a terminal to associate with it, nohup logs everything to an output file, nohup. out . By default, that file is located in whichever directory you started the command in. nohup.
nohup catches the hangup signal (see man 7 signal ) while the ampersand doesn't (except the shell is confgured that way or doesn't send SIGHUP at all). Normally, when running a command using & and exiting the shell afterwards, the shell will terminate the sub-command with the hangup signal ( kill -SIGHUP <pid> ).
Nohup, short for no hang up is a command in Linux systems that keep processes running even after exiting the shell or terminal. Nohup prevents the processes or jobs from receiving the SIGHUP (Signal Hang UP) signal. This is a signal that is sent to a process upon closing or exiting the terminal.
The nohup command can also be used to run programs in the background after logging off. To run a nohup command in the background, add an & (ampersand) to the end of the command.
No, you need to add the nohup to the commands separately.
Something like this is recommended:
nohup sh -c "cmd1 | cmd2" &
Or alternatively:
nohup $SHELL <<EOF & cmd1 | cmd2 EOF
As an alternative to nohup
, I recommend
( cmd1 | cmd2 ) > logfile < /dev/null 2>&1 &
By rerouting stdin, stdout, and sterr from the terminal, this achieves much the same effect as nohup with a syntax that I, at least, prefer.
You always can create a script file and run it with nohup:
echo "cmd1 | cmd2" > nohupScript.sh
nohup nohupScript.sh &
You could start your pipe in a screen
session. Keystroke Ctrl-a and then d will detach the screen session from your terminal. You can then safely exit your terminal; the pipe will continue to run. Use screen -r
to reconnect to the session again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With