Removes the job from the current shell.
disown [-h] [-ar] [jobspec ... | pid ...]
-h marks each job identifier that will not receive a sighup signal when the shell does.
-a removes all jobs.
-r removes a running job.
jobspec (optional): The job identifier to be removed, which can be one or more.
pid (optional): The process ID corresponding to the job to be removed, which can be one or more.
Returns successful unless job control is not enabled or an execution error occurs.
# Demo.
[user2@pc] ssh 192.168.1.4
user2@192.168.1.4's password:
# Press ctrl+z at this time to stop the interaction.
[1]+ Stopped ssh 192.168.1.4
[user2@pc] ssh 192.168.1.7
[email protected]'s password:
# Press ctrl+z at this time to stop the interaction.
[1]+ Stopped ssh 192.168.1.7
[user2@pc] sleep 120 &
[3] 28986
# List jobs and pid information.
[user2@pc] jobs -l
[1]- 28756 Stopped ssh 192.168.1.4
[2]+ 28833 Stopped ssh 192.168.1.7
[3] 28986 Running sleep 120 &
# Delete the running job.
[user2@pc] disown -r
[user2@pc] jobs -l
[1]- 28756 Stopped ssh 192.168.1.4
[2]+ 28833 Stopped ssh 192.168.1.7
# Note that disown only removes the job and does not stop it.
[user2@pc] pgrep -a -u user2 -f 'sleep 120'
28986 sleep 120
# Delete the specified job.
[user2@pc] disown %2
bash: warning: deleting stopped job 2 with process group 28833
[user2@pc] jobs -l
[1]- 28756 Stopped ssh 192.168.1.4
# Note that disown only removes the job and does not stop it.
[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.7'
28833 ssh 192.168.1.7
# Delete all jobs.
[user2@pc] disown -a
bash: warning: deleting stopped job 1 with process group 28756
[user2@pc] jobs -l
# Note that disown only removes the job and does not stop it.
[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.4'
28756 ssh 192.168.1.4
# Demonstrate the effect of the -h option.
[user2@pc] sleep 90 &
[1] 109080
[user2@pc] jobs -l
[1]+ 109080 Running sleep 90 &
[user2@pc] disown -h %1
[user2@pc] exit
# At this time, the previous terminal has been closed. Now open a new terminal to find the job.
[user2@pc] pgrep -a -u user2 -f 'sleep 90'
109080 sleep 90