nohup — Run a command immune to SIGHUP so it survives the terminal closing across all 5 shells
Equivalents in every shell
nohup long-running-cmd &POSIX builtin-like utility (actually `/usr/bin/nohup`). Sets the SIGHUP disposition to "ignore" before exec — when the controlling terminal closes, the process keeps running. `&` backgrounds it so the shell returns immediately. stdout/stderr redirect to `./nohup.out` by default (cwd-dependent); supply `> log 2>&1` to choose your own destination.
nohup long-running-cmd &Same external. Zsh's builtin `disown` does a SIMILAR job for an already-running backgrounded job (`cmd & disown`) — but `disown` only removes the job from the shell's table; the process is still subject to SIGHUP if the shell exits forcefully. `nohup` is the safer one-shot launcher.
nohup long-running-cmd &Same external. Fish has no `disown` builtin equivalent — for fully detached background work use `nohup cmd > log 2>&1 &` or `tmux new -d cmd` (the modern preferred pattern for any non-trivial background process).
Start-Process -WindowStyle Hidden cmd-or-exePowerShell has no `nohup`. `Start-Process` launches and returns immediately; `-WindowStyle Hidden` suppresses a console window; `-NoNewWindow` keeps it in the same console (then the parent must exit cleanly). For a true background JOB within the same pwsh session use `Start-Job { ... }` — but jobs die when the pwsh host exits, just like backgrounded shell jobs without `nohup`.
start /b cmd-or-exe`start /b` runs the command in the same window without waiting. There is NO native cmd equivalent of "survive terminal close" — for that, use `schtasks /create /sc once /tn name /tr "cmd"` to register a Task Scheduler entry, or wrap as a Windows Service.
Worked examples
Start a script that survives the SSH session disconnecting
nohup ./deploy.sh > deploy.log 2>&1 &nohup ./deploy.sh > deploy.log 2>&1 &Detach an already-running foreground job (no nohup wrap)
long-cmd & disownlong-cmd & disownWindows analog — fire and forget without a console window
Start-Process powershell -ArgumentList "-File","script.ps1" -WindowStyle Hiddenstart /b script.batGotchas
- `nohup` ignores SIGHUP but NOT other signals — the process can still be killed by `kill -9 <pid>`, `kill -TERM <pid>`, or the OOM killer. For full resilience plus log management plus auto-restart, use `systemd-run --user --scope` (modern Linux), `tmux new -d`, or a proper service manager (systemd unit, launchd plist).
- `nohup.out` lands in the WORKING DIRECTORY where the command was launched — NOT in `$HOME`. If `nohup ./long-task &` is run from a directory the user later removes (`cd && rm -rf old-dir`), the output is lost. Always explicit-redirect for production: `nohup cmd > /var/log/cmd.log 2>&1 &`.
- When using `nohup` over SSH inside a script, `ssh host 'nohup long-cmd &'` MAY STILL HANG the SSH session because SSH waits for stdout/stderr/stdin to close even after the remote shell exits. Solution: `ssh host 'nohup long-cmd > /dev/null 2>&1 < /dev/null &'` — redirect ALL three streams to detach properly.
- Windows has NO native `nohup`. `Start-Process` returns immediately but the spawned process is still in the SAME logon session — when the user logs off, Windows sends `WM_QUERYENDSESSION` and most processes terminate. For true survival across logoff, register a scheduled task or a service.
- `nohup` reports exit status 127 ("command not found") if the wrapped command doesn't exist — easy to miss because `&` returns 0 immediately. Always confirm with `jobs` (after `nohup`) or `ps -p $!` (immediately after the `&`) that the process actually launched.