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

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

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

disown

Removes the most recent job from the job table

Disown specific job

disown %1

Removes job number 1 from the job table

Disown all jobs

disown -a

Removes all jobs from the job table

Disown only running jobs

disown -r

Removes only currently running jobs

Mark job to ignore SIGHUP

disown -h %1

Marks job 1 to ignore SIGHUP but keeps it in job table

Complete workflow example

# Start a long-running process in background sleep 3600 & [1] 12345 # Check jobs jobs [1]+ Running sleep 3600 & # Disown the job disown %1 # Check jobs again (job is gone) jobs # (no output - job removed from table) # Process continues running even after logout ps aux | grep sleep user 12345 0.0 0.0 7648 616 ? S 10:30 0:00 sleep 3600

Complete example of disowning a background process

Disown by command name

disown %sleep

Disowns the job whose command starts with "sleep"

Disown job containing string

disown %?backup

Disowns the job whose command contains "backup"

Start and immediately disown

long-running-command & disown

Starts a command in background and immediately disowns it

Multiple job disown

disown %1 %2 %3

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

See also