首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
Kill Parent and Children processes/threads by "kill -gid"
service(staff) 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 ofsh 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 sleep11966 11833 sh              sleep 123456711976 11833 sh              sleep 123456711986 11833 sh              sleep 123456711996 11833 sh              sleep 123456712106 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 -- -gidNote: The double dash is needed here for xargs + kill -gid


(1,315 views)
[更多討論] 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體


"Kill Parent and Children processes/threads by "kill -gid"" 傳統頁面(電腦版)

首頁 繪圖設計 工作閒聊 比賽活動 美術討論 標籤 圖片
傳統桌面版
© Vovo2000.com Mobile Version 小哈手機版 2019