disown — Detach a job so it survives shell exit in bash, zsh, fish, PowerShell, and cmd across all 5 shells
Equivalents in every shell
long-job &; disownbash builtin. `disown` (no args) detaches the most recent backgrounded job; `disown %1` targets job #1; `disown -a` all jobs; `disown -h %1` keeps the job in the table but marks it to NOT receive SIGHUP on shell exit (similar effect, different mechanism). Without disown, jobs receive SIGHUP from the shell on exit and terminate.
long-job &; disownzsh builtin, same semantics as bash. zsh's `&!` shortcut combines backgrounding + disowning: `long-job &!` is equivalent to `long-job & disown`. Useful in scripts. zsh also supports `disown %1 %2` to detach multiple jobs in one call.
disown (jobs -p)fish builtin (added in fish 2.3, 2016). `disown` with no args removes the most recent job; `disown PID` targets a PID directly (not `%N` job-spec — fish lacks job-spec syntax). `disown (jobs -p)` detaches all current background jobs in one go.
Start-Process .\long-job.exe -NoNewWindowpwsh has no direct `disown` — `Start-Process` already detaches the launched process (no parent-child SIGHUP relationship on Windows). `Start-Job` runs scripts in a background runspace; jobs survive shell exit only if started via `Start-ThreadJob` with `-Persist` or wrapped in a `Register-ScheduledJob`. To detach an already-running pwsh-spawned process: extract the `[Process]` and let it run — pwsh exit doesn't SIGHUP it.
start /b long-job.exe`start /b` runs a command without a new window and without parent association. cmd has NO job-table — backgrounded processes have no SIGHUP equivalent; closing the parent cmd window doesn't kill the child (unlike Linux where `set -e huponexit` triggers SIGHUP). The detachment is essentially automatic.
Worked examples
Start a long backup, then close the SSH session without killing it
rsync -av /data backup-server:/data &
disown
exitrsync -av /data backup-server:/data &
disown
exitStart-Process pwsh -ArgumentList '-File backup.ps1' -NoNewWindow
exitDetach ALL current background jobs at once
disown -adisown (jobs -p)Detach but KEEP the job listed in the job table (for `jobs` visibility) — mark as no-SIGHUP only
disown -h %1Gotchas
- `disown` does NOT redirect stdout/stderr — the detached process keeps writing to the original terminal. After the shell exits, those writes get a SIGPIPE and the process either crashes (most apps) or silently loses output (apps that handle SIGPIPE). For true detachment from the terminal, use `nohup long-job > out.log 2>&1 &` instead (nohup also handles SIGHUP redirection in one call).
- fish has had `disown` since 2.3 (2016), but predates many fish tutorials online that say "fish has no disown — use nohup". Outdated advice. Verify with `disown --help` on your fish version.
- pwsh `Start-Job` background runspaces DO terminate when the parent pwsh exits (unlike bash backgrounded processes). For pwsh jobs that survive parent exit, use `Start-Process pwsh -ArgumentList "-File script.ps1"` (a separate process, not a runspace) OR register the job as a scheduled task via `Register-ScheduledJob`.
- cmd `start /b` detaches but the child process still inherits the parent's console handle — closing the parent cmd window closes the console, which sends `CTRL_CLOSE_EVENT` to the child (a 5-second graceful-shutdown signal). True survival across console closure requires `start /b cmd.exe /c "long-job.exe"` (intermediate cmd absorbs the close event) or scheduling via `schtasks /create`.
- On Linux, the default shell behavior of SIGHUP-ing children on exit is controlled by `shopt huponexit` (bash) — `shopt -s huponexit` enables it. Many distros DON'T enable it by default, so backgrounded processes survive shell exit WITHOUT `disown`. Verify before relying on `disown` for portability.