disown Command
The disown command removes jobs from the shell's job table, preventing the shell from sending SIGHUP signals to those processes when the shell exits. This allows processes to continue running after logout.
Syntax
Description
The disown command removes jobs from the shell's active job list. When a job is disowned, the shell will not send a SIGHUP signal to it when the shell terminates, allowing the process to continue running independently.
Key features:
- Removes jobs from shell job control
- Prevents SIGHUP signals on shell exit
- Allows processes to survive logout
- Works with background jobs
- Built-in shell command
Common Options
| Option | Description |
|---|---|
-a |
Remove all jobs from the job table |
-r |
Remove only running jobs |
-h |
Mark jobs so they don't receive SIGHUP (but keep in job table) |
jobspec |
Specific job to disown (e.g., %1, %2) |
Job Specifications
| Format | Description |
|---|---|
%n |
Job number n |
%string |
Job whose command begins with string |
%?string |
Job whose command contains string |
%% or %+ |
Current job (most recent) |
%- |
Previous job |
Examples
Disown most recent job
Removes the most recent job from the job table
Disown specific job
Removes job number 1 from the job table
Disown all jobs
Removes all jobs from the job table
Disown only running jobs
Removes only currently running jobs
Mark job to ignore SIGHUP
Marks job 1 to ignore SIGHUP but keeps it in job table
Complete workflow example
Complete example of disowning a background process
Disown by command name
Disowns the job whose command starts with "sleep"
Disown job containing string
Disowns the job whose command contains "backup"
Start and immediately disown
Starts a command in background and immediately disowns it
Multiple job disown
Disowns multiple specific jobs
Common Use Cases
- Long-running processes: Keep processes running after SSH logout
- Background services: Start temporary services that should persist
- Data processing: Run lengthy data processing jobs independently
- Downloads: Continue downloads after closing terminal
- Monitoring: Run monitoring scripts that should survive session
Comparison with Alternatives
| Command | When to Use | Behavior |
|---|---|---|
disown |
After starting a process | Removes from job control |
nohup |
Before starting a process | Immune to SIGHUP from start |
screen |
Interactive sessions | Detachable terminal sessions |
tmux |
Multiple terminal sessions | Terminal multiplexer |