首頁 美術繪圖 | 美術設計 | 熱門標籤 | 首選 | 首頁宣傳 | 近期作品 論壇: 發表 | 美術工作 | 美術比賽 | 展覽活動 | 美術相關 | 一般討論 | 美術同好 CG 討論 :: Photoshop | Painter | 3D 行動 | AMP

【 立即註冊 】 : 更改個人資料 : : 登入

會員名稱: 登入密碼: 保持登入

Kill Parent and Children processes/threads by "kill -gid"

發表新主題 回覆主題 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體

| 1頁, 共1
人氣點閱:2723 發表人
Kill Parent and Children processes/threads by "kill -gid" 2014-11-19 14:29
/ / /

List the group process by ps "-o" custom format command



Assume you are running a bash script which invokes lots of
sh child-threads e.g. "sh sleep 1234567"

%p == process id
%r == group process id
%c == command line (e.g. "sh" here)
%a == command line argument (e.g. "sleep 1234567" here)

代碼:

$ ps xf -o "%p %r %c %a"  | grep 1234567 | grep sleep

11966 11833 sh              sleep 1234567
11976 11833 sh              sleep 1234567
11986 11833 sh              sleep 1234567
11996 11833 sh              sleep 1234567
12106 11833 sh              sleep 1234567



Then, the 2nd colume "11833" is the group process"
You can just use kill -11833 (with single dash before group id)
to kill the all five child sleep process/threads.

Combine group-thread kill -group_process_id with xargs


代碼:


$ ps xf -o "%p %r %c %a"  | grep 1234567 | grep sleep | tail -1 | awk '{print $2}' |  xargs -Igid kill -- -gid


Note: The double dash is needed here for xargs + kill -gid
service



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: staff
註冊: 2007-03-30
發表: 48

V幣: 2703





資訊相關理論、技術、管理、應用、產品等
發表新主題 回覆主題