nohup is a standard Unix and Linux command that runs another program with the SIGHUP signal ignored, so the program keeps running when the controlling terminal closes or the user logs out. Among Linux processes, it is the simplest tool for keeping a long job alive beyond the session that started it.
The name stands for no hangup. The utility is specified by POSIX, ships in GNU coreutils and BusyBox, and works identically in every common shell. It does not place a process in the background, schedule it or supervise it; it changes one signal disposition and adjusts output redirection, then replaces itself with the target command.
How nohup protects a process from SIGHUP
When a terminal session ends, the kernel sends SIGHUP to the session’s foreground process group, and most shells forward it to their background jobs as well. The default action for SIGHUP is to terminate the process, which is why a long compile or data copy normally dies when an SSH connection drops.
nohup sets the disposition of SIGHUP to SIG_IGN and then calls exec to load the requested program in the same process. Because ignored signals remain ignored across exec, the new program inherits the protection and never sees the hangup. The process ID stays the same, so the job appears in ps under its own command name, not as nohup.
nohup also handles terminal-bound file descriptors, because writing to a closed terminal would otherwise fail or raise SIGPIPE. The table below summarizes what GNU nohup does with each standard stream.
| Stream | Condition | Action taken by nohup |
|---|---|---|
| Standard output | Connected to a terminal | Appended to nohup.out in the current directory |
| Standard output | Current directory not writable | Appended to $HOME/nohup.out |
| Standard error | Connected to a terminal | Sent to the same place as standard output |
| Standard input | Connected to a terminal | Replaced with an unreadable descriptor |
| Any stream | Already redirected by the user | Left unchanged |
Syntax, exit codes and correct usage
The basic form is nohup command arguments &. The trailing ampersand is essential in interactive use: nohup itself does not detach, so without & the shell waits for the command and the terminal stays occupied. A typical production invocation also sets an explicit log file, as in nohup ./backup.sh > backup.log 2>&1 &.
nohup reports its own failures through reserved exit statuses, which scripts can test to tell a launcher problem from a failure of the job itself.
| Exit status | Meaning |
|---|---|
| 125 | nohup itself failed, for example it could not open nohup.out |
| 126 | The command was found but could not be executed |
| 127 | The command was not found |
| Any other value | The exit status of the command that nohup ran |
Because nohup uses exec, it can only start an executable program, not a shell builtin, alias or function. To protect a pipeline or compound command, wrap it in a shell: nohup sh -c 'step1 && step2' > job.log 2>&1 &. The $! variable then holds the process ID for later monitoring or termination with kill.
nohup compared with disown, setsid and terminal multiplexers
Several mechanisms keep a process alive after logout, and they differ in when the decision is made and how much isolation they provide. nohup must be chosen before the command starts, while job control builtins can rescue a job already running.
| Method | Applied | Effect | Output and reattachment |
|---|---|---|---|
| nohup | Before start | Ignores SIGHUP | File only, no reattachment |
| disown | After start | Removes the job from the shell job table | No change, no reattachment |
| setsid | Before start | Creates a new session without a terminal | Must be redirected manually |
| screen or tmux | Before start | Keeps a virtual terminal alive | Full reattachment to live output |
| systemd-run or a unit | Before start | Runs under the service manager | Journal logging, restart policies |
The bash builtin disown -h marks a job so the shell does not forward SIGHUP, which makes it the closest after-the-fact equivalent of nohup. setsid offers stronger detachment because the process has no controlling terminal at all, so no terminal hangup can ever reach it.
Limitations and common mistakes with nohup
nohup protects against exactly one signal. A process started with it still dies on SIGTERM, SIGKILL, an OOM killer decision or a reboot, and it is never restarted. For anything that must stay up reliably, a systemd service or another supervisor is the appropriate tool.
On many modern distributions, systemd-logind can be configured with KillUserProcesses=yes, which terminates every process in the user’s session scope at logout regardless of signal dispositions. In that configuration, nohup alone is not sufficient, and the job should be started with systemd-run --user together with lingering enabled, or as a proper unit.
The table below lists frequent symptoms, their causes and the usual fix.
| Symptom | Cause | Fix |
|---|---|---|
| Terminal stays blocked | Missing & after the command | Add & or use Ctrl+Z and bg |
| Disk fills with nohup.out | Unbounded output appended to one file | Redirect to a rotated log or /dev/null |
| Job still dies at logout | logind kills the session scope | Use systemd-run --user or a service |
| Job stops when reading input | Program expects terminal input | Supply input from a file or redirect stdin |
| Program exits on hangup anyway | Program installs its own SIGHUP handler | Use setsid or a supervisor |
- Programs may override the setting: an application that installs a SIGHUP handler, often to reload configuration, will act on hangups despite nohup.
- Relative paths in nohup.out: the file lands in the working directory at launch time, which surprises users who start jobs from varying directories.
- No priority change: nohup does not alter scheduling, so combine it with
nicewhen a background job should yield CPU time.
Explained without jargon
When you close a terminal window or lose a remote connection, Linux tells every program started from it that the line has been hung up, and most programs simply quit. nohup is a small helper that tells a program to ignore that message.
It works like asking a colleague to keep working even after you leave the office. The work continues, and anything the program would have printed on screen is saved to a file instead, so it can be read later. It does not watch over the program or restart it if something else goes wrong.
A typical use case
A database administrator connects over SSH from a hotel network to export a 200 GB table from a Linux server. The export is expected to take about three hours, and the connection has dropped twice already that evening. Instead of running the dump directly, the administrator types nohup pg_dump -Fc sales > /backup/sales.dump 2> /backup/sales.err & and notes the process ID printed by the shell.
Forty minutes later the SSH session drops again. After reconnecting, the administrator checks the process with ps -p followed by the ID and watches the dump file grow with ls -lh. The export finishes unattended shortly before midnight, and the error file stays empty, confirming a clean result. For the next nightly export, the team moves the same command into a scheduled systemd timer so it no longer depends on any interactive session.