Skip to content
shellmap

disownDetach a job so it survives shell exit in bash, zsh, fish, PowerShell, and cmd across all 5 shells

Equivalents in every shell

Bashunix
long-job &; disown

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

Zshunix
long-job &; disown

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

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

PowerShellwindows
Start-Process .\long-job.exe -NoNewWindow

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

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

Bash
rsync -av /data backup-server:/data &
disown
exit
Fish
rsync -av /data backup-server:/data &
disown
exit
PowerShell
Start-Process pwsh -ArgumentList '-File backup.ps1' -NoNewWindow
exit

Detach ALL current background jobs at once

Bash
disown -a
Fish
disown (jobs -p)

Detach but KEEP the job listed in the job table (for `jobs` visibility) — mark as no-SIGHUP only

Bash
disown -h %1

Gotchas

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

WSL & PowerShell Core notes

pwshWindows has no SIGHUP — closing a pwsh window does not send a hangup signal to spawned processes (it sends `CTRL_CLOSE_EVENT` only to direct console children). Spawned processes via `Start-Process` (which detaches console association) survive automatically. The closest pwsh idiom to `disown` is just `Start-Process` with `-WindowStyle Hidden`.
WSLWSL inherits Linux SIGHUP semantics — `disown` matters in WSL bash. Useful pattern: kick off a WSL `long-job &; disown; exit` and the job continues after the WSL terminal closes. The job lives until the WSL distribution itself shuts down (`wsl --shutdown`).

Common tasks using disown

Related commands