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 [ARG...]
or: `nohup` OPTION
PARAMETERS
COMMAND
The command to be executed, which will ignore the SIGHUP signal.
[ARG...]
Optional arguments passed to the `COMMAND`.
`--help`
Display a help message and exit.
`--version`
Output version information and exit.
DESCRIPTION
`nohup` (short for "no hang up") is a POSIX command that runs a specified command such that it ignores the SIGHUP (hang-up) signal. This signal is typically sent to a process by the operating system when its controlling terminal is closed or disconnected, which would normally terminate the process. By using `nohup`, long-running processes can continue executing in the background even after the user logs out or the network connection is lost.
When a command is run with `nohup`, its standard output and standard error are, by default, redirected to a file named `nohup.out` in the current directory. If the current directory is not writable, the output is redirected to `$HOME/nohup.out`. Standard input is redirected from `/dev/null`. It's important to note that `nohup` itself does not automatically background the command; to run a process in the background and disconnect from the terminal, one must typically append `&` to the command. This combination makes `nohup` a crucial utility for managing persistent background tasks on remote servers.
CAVEATS
- `nohup` does not automatically send a process to the background; you must explicitly append `&` (ampersand) to the command to run it in the background.
- `nohup` primarily handles the SIGHUP signal. Other signals (e.g., SIGTERM, SIGKILL) can still terminate the process.
- Default output redirection to `nohup.out` can lead to large files if not managed. Always consider explicit redirection (`> file.log 2>&1`) for better control.
- Standard input is redirected from `/dev/null`, so interactive commands will not work as expected.
OUTPUT REDIRECTION
By default, `nohup` redirects standard output and standard error to a file named `nohup.out` in the current working directory. If `nohup.out` cannot be created or is not writable, it attempts to write to `$HOME/nohup.out`. To redirect output to a different file, you must explicitly do so, for example: `nohup command > output.log 2>&1 &`.
INPUT HANDLING
`nohup` automatically redirects standard input to `/dev/null`. This means that the command being run with `nohup` will not be able to receive any input from the terminal after it is started. This is generally desired for background processes but is an important consideration for interactive scripts.
HISTORY
`nohup` has been a fundamental utility in Unix-like operating systems since their early days. It addresses the basic need to run processes that persist beyond the lifetime of a user's login session. Its design is simple and effective, predating more complex session management tools like `screen` and `tmux`, but it remains a widely used and essential command for its specific purpose.
SEE ALSO
`disown(1)`, `screen(1)`, `tmux(1)`, `bg(1)`, `jobs(1)`, `at(1)`