在標題中 - 如何殺死zsh中的所有後臺進程?如何殺死zsh中的所有後臺進程?
8
A
回答
9
。這是zsh,不需要外部工具。
如果你想殺死作業號N:
function killjob()
{
emulate -L zsh
for jobnum in [email protected] ; do
kill ${${jobstates[$jobnum]##*:*:}%=*}
done
}
killjob N
0
0
這同時適用於ZSH和Bash:
: '
killjobs - Run kill on all jobs in a Bash or ZSH shell, allowing one to optionally pass in kill parameters
Usage: killjobs [zsh-kill-options | bash-kill-options]
With no options, it sends `SIGTERM` to all jobs.
'
killjobs() {
local kill_list="$(jobs)"
if [ -n "$kill_list" ]; then
# this runs the shell builtin kill, not unix kill, otherwise jobspecs cannot be killed
# the `[email protected]` list must not be quoted to allow one to pass any number parameters into the kill
# the kill list must not be quoted to allow the shell builtin kill to recognise them as jobspec parameters
kill [email protected] $(sed --regexp-extended --quiet 's/\[([[:digit:]]+)\].*/%\1/gp' <<< "$kill_list" | tr '\n' ' ')
else
return 0
fi
}
@zyx答案並沒有爲我工作。
更多在這裏:https://gist.github.com/CMCDragonkai/6084a504b6a7fee270670fc8f5887eb4
0
小的調整@ ZXY的迴應......
在我的系統,我發現,暫停的作業不使用默認的終止信號正常死亡。我不得不將其更改爲kill -KILL
以使suspended
後臺作業正常死亡。
alias killbg='kill -KILL ${${(v)jobstates##*:*:}%=*}'
請特別注意周圍的單引號。如果您切換到雙引號,則需要轉義每個「$」。請注意,您不能使用function
來包裝此命令,因爲該函數將增加$jobstates
數組,導致該函數嘗試自行查殺......必須使用別名。
以上killjob
腳本是有點多餘,因爲你可以這樣做:
kill %1
更少的鍵盤操作和它已經建成zsh
。
0
相關問題
- 1. 殺死後臺進程
- 2. 如何殺死pm2 - 無後臺進程
- 3. 如何殺死所有異步進程
- 4. 如何殺死Linux中沒有被殺死的進程
- 5. bash關機掛鉤;或者,殺死所有後臺進程,當主進程被殺死
- 6. C# - 如何殺死在後臺程序運行的excel進程
- 7. 如何殺死/停止後臺線程?
- 8. 如何殺死進程窗口的所有遞歸子進程
- 9. 如何殺死後臺運行的IEDriver exe進程(Selenium webdriver)?
- 10. 如何殺死一個腳本創建的後臺進程
- 11. 殺死進程殺死其他進程
- 12. 如何殺死OS X中的所有窗口進程
- 13. 如何殺死python中的所有子進程
- 14. 如何殺死多進程中的所有Pool worker?
- 15. 如何殺死ruby Thor中的所有進程停止?
- 16. 如何殺死當前shell中的所有子進程?
- 17. 殺死所有進程,強制所有進程停止
- 18. 如何正確殺死Android活動,這不是後臺進程
- 19. 如何殺死Android應用後臺進程?
- 20. Bash:殺死子進程中的所有進程
- 21. 如何殺死nohup進程?
- 22. 如何殺死所有線程?
- 23. 殺死進程
- 24. 殺死進程
- 25. 殺死進程
- 26. 安全殺死一個進程和所有後代的方法
- 27. 殺死在while循環後臺進程中創建的PID
- 28. 如何殺死在後臺進程中運行的Android應用程序
- 29. 如何殺死spacemacs中的進程
- 30. 如何殺死Windows Mobile中的進程?
作爲'zsh' noob,介意解釋第一行? –
@ZachRiggle它在'man zshexpn'和'man zshmodules'中:'$ jobstates'是一個關聯數組參數,'(v)'只選擇這個數組中的值,'#'使zsh從開始字符串,選擇刪除最少冗長模式,'*:*:':使zsh刪除每個值的前兩個冒號分隔字段的模式(數組參數上的'#'應用於每個值),'%'類似'#',但是對於字符串結尾和'= *'會使zsh在包含符號本身的最後一個符號之後移除所有內容。每個'$ jobstates'的值看起來像'job-state:mark:pid = state ...'。 – ZyX
看來我在這裏有一個錯誤:如果整個管道被暫停,它不起作用。 – ZyX