LinuxCommandLibrary

disown

Detach a background process from the shell

TLDR

Disown the current job

$ disown
copy

Disown a specific job
$ disown %[job_number]
copy

Disown all jobs
$ disown -a
copy

Keep job (do not disown it), but mark it so that no future SIGHUP is received on shell exit
$ disown -h %[job_number]
copy

SYNOPSIS

disown [-ar] [-h] [jobspec ... | pid ...]

PARAMETERS

jobspec ... | pid ...
    One or more job identifiers (e.g., %1, %jobname) or process IDs to disown. If omitted and neither -a nor -r is supplied, the currently running job is acted upon.

-a
    Remove all jobs from the job table. This makes them immune to SIGHUP upon shell exit.

-r
    Remove only running jobs from the job table. This makes them immune to SIGHUP upon shell exit.

-h
    Mark each jobspec or PID so that a SIGHUP is not sent to the job if the shell receives a SIGHUP. Unlike the default behavior, this option does not remove the job from the job table, meaning it will still appear in jobs output.

DESCRIPTION

The disown command is a shell built-in utility, primarily found in Bash and Zsh, used to remove jobs from the shell's active job table. By removing a job from this table, the shell will no longer send a SIGHUP signal to that process when the shell exits. This is particularly useful for long-running processes that you wish to continue executing in the background even after closing the terminal or logging out.

Typically, when a shell exits, it sends a SIGHUP to all processes in its job table. disown prevents this by severing the shell's association with the process. Once a job is disowned (without the -h option), it can no longer be managed by the shell's job control commands (like fg or bg) and will not appear in the output of the jobs command.

It's commonly used after a process has been suspended (e.g., with Ctrl+Z) and then moved to the background (with bg), to ensure its continued execution independent of the shell session.

CAVEATS

disown is a shell built-in command, primarily available in Bash and Zsh, not a standalone executable found in /usr/bin.
Once a process is disowned (without -h), it cannot be brought back to the foreground (fg) or backgrounded (bg) using shell job control commands.
While disown prevents SIGHUP from the shell, it does not guarantee a process will run indefinitely; it can still be killed by other signals, system shutdowns, or resource limits.
It only affects jobs started within the current shell session.

USE CASES

disown is ideal when you start a long-running process interactively, realize you need to close your terminal, and want the process to continue. A common sequence is:
1. Start command: long_command
2. Suspend with Ctrl+Z
3. Send to background: bg
4. Detach from shell: disown

COMPARISON WITH NOHUP

While both disown and nohup aim to allow processes to survive shell exit, they differ in their approach. nohup is an external command used to launch a process from the start, ensuring it ignores SIGHUP from the outset and often redirects its output to nohup.out. disown, on the other hand, is a shell built-in used after a job has already been started within the current shell, allowing you to retrospectively detach it from job control.

HISTORY

The concept of detaching processes from the shell's job control has been a feature of interactive Unix-like shells for decades. disown specifically emerged as a built-in command in shells like Bash and Zsh to provide fine-grained control over job management, complementing older methods like nohup. Its development is tied to the evolution of shell job control features, which became standard in the late 1980s and early 1990s.

SEE ALSO

jobs(1), fg(1), bg(1), nohup(1), screen(1), tmux(1)

Copied to clipboard