從當(dāng)前的shell中移除作業(yè)。
disown [-h] [-ar] [jobspec ... | pid ...]
從當(dāng)前shell的作業(yè)列表中移除全部作業(yè)。
從當(dāng)前shell的作業(yè)列表中移除指定的一到多個(gè)作業(yè)。
從當(dāng)前shell的作業(yè)列表中移除正在運(yùn)行的作業(yè)。
標(biāo)記作業(yè),使得它們?cè)诋?dāng)前shell退出后也不會(huì)結(jié)束。
-h 標(biāo)記每個(gè)作業(yè)標(biāo)識(shí)符,這些作業(yè)將不會(huì)在shell接收到sighup信號(hào)時(shí)接收到sighup信號(hào)。
-a 移除所有的作業(yè)。
-r 移除運(yùn)行的作業(yè)。
jobspec(可選):要移除的作業(yè)標(biāo)識(shí)符,可以是一到多個(gè)。
pid(可選):要移除的作業(yè)對(duì)應(yīng)的進(jìn)程ID,可以是一到多個(gè)。
返回成功除非未開(kāi)啟作業(yè)控制或執(zhí)行出現(xiàn)錯(cuò)誤。
# 演示。
[user2@pc] ssh 192.168.1.4
user2@192.168.1.4's password:
# 此時(shí)按下ctrl+z使得交互停止。
[1]+ Stopped ssh 192.168.1.4
[user2@pc] ssh 192.168.1.7
user2@192.168.1.7's password:
# 此時(shí)按下ctrl+z使得交互停止。
[1]+ Stopped ssh 192.168.1.7
[user2@pc] sleep 120 &
[3] 28986
# 列出作業(yè)及pid信息。
[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 &
# 刪除運(yùn)行狀態(tài)的作業(yè)。
[user2@pc] disown -r
[user2@pc] jobs -l
[1]- 28756 Stopped ssh 192.168.1.4
[2]+ 28833 Stopped ssh 192.168.1.7
# 注意disown只是移除作業(yè),并沒(méi)有停止。
[user2@pc] pgrep -a -u user2 -f 'sleep 120'
28986 sleep 120
# 刪除指定的作業(yè)。
[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
# 注意disown只是移除作業(yè),并沒(méi)有停止。
[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.7'
28833 ssh 192.168.1.7
# 刪除全部作業(yè)。
[user2@pc] disown -a
bash: warning: deleting stopped job 1 with process group 28756
[user2@pc] jobs -l
# 注意disown只是移除作業(yè),并沒(méi)有停止。
[user2@pc] pgrep -a -u user2 -f 'ssh 192.168.1.4'
28756 ssh 192.168.1.4
# 演示-h選項(xiàng)的作用。
[user2@pc] sleep 90 &
[1] 109080
[user2@pc] jobs -l
[1]+ 109080 Running sleep 90 &
[user2@pc] disown -h %1
[user2@pc] exit
# 此時(shí)前一個(gè)終端已經(jīng)關(guān)閉,現(xiàn)在打開(kāi)新終端查找該作業(yè)。
[user2@pc] pgrep -a -u user2 -f 'sleep 90'
109080 sleep 90
bash
的作業(yè)控制命令包括bg fg kill wait disown suspend
。set
選項(xiàng)monitor
處于開(kāi)啟狀態(tài)時(shí)才能執(zhí)行;查看作業(yè)控制狀態(tài):輸入set -o
查看monitor
行;執(zhí)行set -o monitor
或set -m
開(kāi)啟該選項(xiàng)。help
命令。