Disown
The disown
command is used to remove a job from the session’s background job table. This means that if you run disown
on a running process, it will no longer be controlled by your current shell session. The use of this command can be beneficial when:
- You want to detach a long-running process from your current terminal but still want it to continue running.
- You need to disconnect from a remote server or session without killing any background processes.
To use disown
, you simply specify the job ID (or a percentage sign %
to refer to all jobs), and the command will be removed from the job table. Here’s an example:
bash
[john@localhost ~]$ jobs
[1] Running ./long_process &
[john@localhost ~]$ disown %1
In this case, disown
removes the process ./long_process
from the background job list.
Special Hack:
One special use of disown
is to detach a process and run it in the background without creating a new job entry. To do this, use disown
after running a command with the &
symbol at the end:
bash
[john@localhost ~]$ ./long_process &
[1] Running ./long_process &
[john@localhost ~]$ disown %1
This way, the process will continue to run in the background, but it won’t be listed as a job when you run jobs
.
Level of Experience:
The use of disown
requires an intermediate level of experience with Linux and shell commands. It’s essential to understand how jobs are managed by the shell and how to detach processes from your current session.
Beginners may find it useful to learn about nohup
, which also allows running a process in the background, but disown
is more versatile and powerful for detached job management.