Skip to content
shellmap

nohupRun a command immune to SIGHUP so it survives the terminal closing across all 5 shells

Equivalents in every shell

Bashunix
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.

Zshunix
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.

Fishunix
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).

PowerShellwindows
Start-Process -WindowStyle Hidden cmd-or-exe

PowerShell 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`.

cmd.exewindows
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

Bash
nohup ./deploy.sh > deploy.log 2>&1 &
Zsh
nohup ./deploy.sh > deploy.log 2>&1 &

Detach an already-running foreground job (no nohup wrap)

Bash
long-cmd & disown
Zsh
long-cmd & disown

Windows analog — fire and forget without a console window

PowerShell
Start-Process powershell -ArgumentList "-File","script.ps1" -WindowStyle Hidden
cmd.exe
start /b script.bat

Gotchas

  • `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.

WSL & PowerShell Core notes

pwshLinux/macOS pwsh can shell out to `/usr/bin/nohup`: `& /usr/bin/nohup long-cmd > log 2>&1 &` works in pwsh because `&` is the call operator (NOT a background marker — that's the trap). Use `Start-Job` for an in-pwsh-session background; for terminal-close survival, the underlying OS `nohup` is the right tool.
WSL`nohup` inside WSL works as on Linux — but the process dies if you close the LAST WSL2 distribution window AND WSL2's VM shuts down (default after 8 seconds idle in `wsl.conf`). To keep WSL2 alive use `wsl --shutdown-timeout 0` semantics or run a sentinel process. For absolute survival pin a Windows Task Scheduler task to invoke `wsl bash -c "nohup ..."` on logon.

Common tasks using nohup

Related commands