从当前的 shell 中移除作业。
概要
disown [-h] [-ar] [jobspec ... | pid ...]
主要用途
- 从当前 shell 的作业列表中移除全部作业。
- 从当前 shell 的作业列表中移除指定的一到多个作业。
- 从当前 shell 的作业列表中移除正在运行的作业。
- 标记作业,使得它们在当前 shell 退出后也不会结束。
选项
-h 标记每个作业标识符,这些作业将不会在shell接收到sighup信号时接收到sighup信号。-a 移除所有的作业。-r 移除运行的作业。
参数
jobspec(可选):要移除的作业标识符,可以是一到多个。
pid(可选):要移除的作业对应的进程 ID,可以是一到多个。
返回值
返回成功除非未开启作业控制或执行出现错误。
例子
[user2@pc] ssh 192.168.1.4user2@192.168.1.4's password:# 此时按下ctrl+z使得交互停止。[1]+ Stopped ssh 192.168.1.4[user2@pc] ssh 192.168.1.7user2@192.168.1.7's password:[1]+ Stopped ssh 192.168.1.7[user2@pc] sleep 120 &[3] 28986[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 &[user2@pc] disown -r[user2@pc] jobs -l[1]- 28756 Stopped ssh 192.168.1.4[2]+ 28833 Stopped ssh 192.168.1.7[user2@pc] pgrep -a -u user2 -f 'sleep 120'28986 sleep 120[user2@pc] disown %2bash: warning: deleting stopped job 2 with process group 28833[user2@pc] jobs -l[1]- 28756 Stopped ssh 192.168.1.4[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.7'28833 ssh 192.168.1.7[user2@pc] disown -abash: warning: deleting stopped job 1 with process group 28756[user2@pc] jobs -l[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.4'28756 ssh 192.168.1.4[user2@pc] sleep 90 &[1] 109080[user2@pc] jobs -l[1]+ 109080 Running sleep 90 &[user2@pc] disown -h %1[user2@pc] exit[user2@pc] pgrep -a -u user2 -f 'sleep 90'109080 sleep 90
注意
bash的作业控制命令包括bg fg kill wait disown suspend。- 该命令需要
set选项monitor处于开启状态时才能执行;查看作业控制状态:输入set -o查看monitor行;执行set -o monitor或set -m开启该选项。 - 该命令是 bash 内建命令,相关的帮助信息请查看
help命令。
