What is disown?
Shells like Bash send a 'terminate!' signal (SIGHUP) to all jobs they manage when the terminal is closed. `disown` removes a specific job from the shell's management list (its 'lineage'), preventing it from dying when the shell terminates.
When to use it?
- When you forgot nohup: Used when you've run a long-running task without `nohup`, need to leave, but don't want the task to stop.
- Workflow: Used in the sequence: suspend while running (Ctrl+z) -> move to background (bg) -> disown ownership (disown).
- :
- Shell Built-in Command: It's a feature built into the shell (Bash, Zsh, etc.), not a separate program.
Main Options (Shell)
When used without options, it targets the most recent job. To specify a particular job, use its 'Job ID'.
1. 기본 사용 및 대상 지정
2. 상태 보존
3. 도움말
Generated command:
Try combining the commands.
Description:
`disown` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Scenarios (Essential Pattern)
`disown` is often used as a set with `Ctrl+z` and `bg`, rather than alone.
Scenario: Accidentally ran backup without nohup!
You ran `backup.sh` without `nohup`, and it takes an hour. Closing the terminal will stop the backup. Here's how to save it.
3-Step Rescue (Step-by-Step)
Follow these steps on your keyboard:
- 1. Press `Ctrl + z` in the running terminal to temporarily suspend the job.
- 2. Enter the `bg` command to restart the stopped job in the background.
- 3. Enter the `disown` command to sever its connection with the shell.
Selectively Disown a Specific Job
disown %2
Disowns only job number 2, as confirmed by `jobs`.
Keep in List but Protect (-h)
disown -h %1
Makes it visible when you type the `jobs` command, but prevents it from dying when the terminal closes.
Installation
`disown` is a built-in command in shells like Bash and Zsh, so no separate installation is required.
No Installation Needed
If you are using a Linux terminal, it is already installed.
Tips & Cautions
Useful Tips
- Job ID vs PID: `disown` uses the shell's job number (Job ID, e.g., %1), not the process ID (PID, e.g., 1234). Don't forget to prepend with `%`.
- Output Not Retained: While `nohup` creates a `nohup.out` file, `disown` detaches an already running process, so its output might be lost. Preserving output would require complex methods like using `gdb`.
- How to Verify: After `disown` (without options), the job disappears from the `jobs` list. To check if the process is still alive, you need to use `ps -ef | grep command`.