Thursday, January 15, 2015

How to kill whole process group (parent + child process)

This is very easy, and all this while I have been using ps with grep and awk, just to get the parent and child process PID, and feed it to kill command to kill the whole lot of them. Now no more, that is why reading the man page is very beneficial ;). To kill the whole group process, please see below example.

Let's say I want to kill teamviewer, and it's child processes:

check what is teamviewer and its children's PID:


$ pstree -Gap 31458

teamviewerd,31458 -f

├─{teamviewerd},31460

├─{teamviewerd},31461

├─{teamviewerd},31462

├─{teamviewerd},31463

├─{teamviewerd},31464

├─{teamviewerd},31465

├─{teamviewerd},31466

├─{teamviewerd},31549

└─{teamviewerd},24892

run kill to the PID of parent, and put - sign in front of the PID, to signal the whole group killing:
$ kill -TERM -31458

no more PID 31458, with the children processes
$ pstree -Gap 31458

No comments:

Post a Comment