If you select the process at the top of the tree you want kill, then press F9 followed by Enter it will close the process and the entire process tree in one go. In the screen shot below this action would cause Chrome and all sub process to be closed.
If it is a process group you want to kill, just use the kill(1) command but instead of giving it a process number, give it the negation of the group number. For example to kill every process in group 5112, use kill -TERM -- -5112 .
Pro tip: pkill exists, you can replace the whole problematic hack with one command. Show activity on this post. my $pid = `ps -ef | grep '$processName' | grep -v grep | awk '{print \$2}'`; print $pid; system("kill -9 $pid"); This one works!!!
What's the best way to kill a process and all its child processes from a Perl script? It should run at least under Linux and Solaris, and not require installation of any additional packages.
My guess would be to get a list of all processes and their parents by parsing files in /proc or by parsing the output of ps
(neither of which seems portable between Linux and Solaris); and then killing all processes in the tree (which seems prone to race conditions).
I could live with the race conditions in this particular case, but how do I portably get the process list?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With