nohup
Run command, ignoring hangup signals
TLDR
Run a process that can live beyond the terminal
Launch nohup in background mode
Run a shell script that can live beyond the terminal
Run a process and write the output to a specific file
SYNOPSIS
nohup command [arguments...]
PARAMETERS
command
The command to execute.
arguments
Any arguments to pass to the command.
--help
Display help and exit.
--version
Output version information and exit.
DESCRIPTION
The nohup command in Linux allows you to execute a command that will continue running even after you log out of the shell or the terminal session is closed. It achieves this by ignoring the SIGHUP (hangup) signal, which is typically sent to processes when a terminal disconnects.
When nohup is used, if the standard output is a terminal, it redirects the output to a file named nohup.out in the current directory or $HOME if the current directory is not writable. Similarly, the standard error is redirected to the standard output and effectively ends up in the same nohup.out file.
This makes nohup exceptionally useful for running long-running processes, such as server applications, data processing scripts, or any task that requires continuous operation without user intervention. When you start the process with nohup it continues to run in the background even if your shell disconnects. Be careful when using with pipes to ensure all stages output properly.
CAVEATS
If nohup.out cannot be created or written to, the command will not be started. Ensure the current directory or $HOME is writable. The command is run with the SIGHUP signal ignored, but other signals are still handled as normal.
REDIRECTION
To redirect output to a specific file, use standard shell redirection:
nohup command > myoutput.txt 2>&1 &
BACKGROUNDING
The '&' symbol at the end of the command line starts the process in the background, allowing you to continue using the terminal.
SIGNAL HANDLING
While nohup ignores SIGHUP, the process is still susceptible to other signals, such as SIGINT (Ctrl+C) or SIGTERM. To gracefully stop a process, use appropriate signals with kill or killall command.
HISTORY
nohup has been a standard Unix utility for a very long time, appearing in early versions of Unix. Its primary purpose has always been to allow users to start processes that would continue running even after they disconnected from the system. This was particularly important in the days of dial-up connections, where disconnections were common. It remains useful in modern systems for similar reasons, enabling users to start persistent processes that are not tied to a specific terminal session.