Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The disown command is a Bash shell builtin that removes a specified job from the shell’s internal job control table. By removing the job from this table, the shell relinquishes tracking of the process, ensuring the shell will not broadcast a SIGHUP (Hangup) signal to that process if the shell receives a SIGHUP or terminates under specific configurations.
disown [-ar] [-h] [jobspec ...]

Technical Mechanics

When a process is executed in the background (e.g., appended with & or suspended and resumed via bg), Bash assigns it a job specification (jobspec) and tracks it in an internal array. Bash broadcasts a SIGHUP to all tracked child processes in this array under two specific conditions:
  1. The shell itself receives a SIGHUP (such as when the controlling terminal emulator is closed).
  2. The shell is an interactive login shell terminating normally, and the huponexit shell option is enabled.
Executing disown alters this state in one of two ways, depending on the flags provided: it either completely excises the process from the job table, or it modifies the job’s internal flags to bypass the SIGHUP broadcast while maintaining its presence in the table.

Parameters and Flags

  • jobspec: The job identifier (e.g., %1, %2). If omitted, disown defaults to the current job (represented by %+ or %%).
  • -h: Retains the job in the job control table but sets a flag preventing the shell from sending SIGHUP to it. The job remains visible to the jobs command.
  • -a: Applies the disown operation to all jobs currently in the job table.
  • -r: Restricts the operation to running jobs only, ignoring any jobs that are currently stopped (suspended).

State Transition Example


# 1. Process is spawned in the background
sleep 300 &

# Output: [1] 14592


# 2. Process is tracked in the job table
jobs

# Output: [1]+  Running                 sleep 300 &


# 3. Process is excised from the job table
disown %1


# 4. Job table is now empty; shell will not send SIGHUP to PID 14592
jobs

# Output: (empty)

I/O Stream Behavior

disown operates strictly on signal propagation and job tracking; it does not detach the process from the controlling terminal’s file descriptors. If a disowned process attempts to read from stdin or write to stdout/stderr after the controlling terminal is destroyed, the process will encounter an I/O error (typically resulting in a SIGPIPE or immediate termination). Furthermore, closing the terminal emulator itself may cause the terminal line discipline to send a SIGHUP directly to the session leader and its foreground process group, independent of the shell’s job control mechanisms.
Master Bash with Deep Grasping Methodology!Learn More