nohup on Linux: Keep Processes Running After Terminal Closes
Regardless of whether the programs running in the shell are in the foreground or background, they will be terminated when the user disconnects or closes the terminal.
This happens because Jobs receive the SIGHUP (hangup) signal, which is a notice from the terminal to its child processes that a disconnection has occurred.
So that this doesn't happen, the nohup command on Linux makes the process immune to the signal SIGHUP, allowing it to continue running even if the terminal closes or the connection drops.
This way, the nohup utility executes the specified command without attaching it to any terminal, in a manner that is immune to connection drops and disconnections.
In this example, nohup will execute the command find / -name uira* and send the output to arquivos_encontrados, and it will also be executed in the background:
$ nohup find / -name uira* > arquivos_encontrados &
Nohup executes the specified command, but does not allow it to receive any input data through the terminal.
All outputs (STDOUT), including error messages (STDERR), will be written to the nohup.out file in the working directory or the local directory.
You can use nohup in the foreground or in the background. The most common is to run it in the background by placing the "&" at the end of the command line.
Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.
Did you like it? Share
That was just one piece. The course teaches the whole path — from your first command to exam day.