One Line Linux Command to Kill Parent Process and Spawned Children in A Group

Computer Screen Photo by Markus Spiske on UnsplashIn Linux, if you’d like to kill a command and all processes spawned by that command do this (in our example the command “parent” is example.py):

This will kill the “example.py” process and anything that it spawned.

How it works:

To kill all processes of a group the command is

To get the group id you do the ps command using the arguments as shown, grep it for your command, but formatting example.py with quotes and using the bracket for the first letter (this filters out the grep command itself) then filter it through awk to get the second field which is the group id. The tail -1 gets rid of duplicate group ids. Yout put all of that in a variable using the $() syntax and voila – you get the group id. So you substitute that $(mess) for that -groupid in the kill command above.

This field is required.

Leave a Reply

Your email address will not be published. Required fields are marked *

*******************************************************