Special thanks to tanager and Speakus for contributions on $PID remaining spaces and OSX compatibility.
Explanation
kill -9 -"$PGID" => Send signal 9 (KILL) to all child, grandchild…
PGID=$(ps opgid= "$PID") => Retrieve the Process-Group-ID from any Process-ID of the tree, not only the Process-Parent-ID. A variation of ps opgid= $PID is ps -o pgid --no-headers $PID where pgid can be replaced by pgrp. But:
ps inserts leading spaces when PID is less than five digits and right aligned as noticed by tanager. You can use: PGID=$(ps opgid= "$PID" | tr -d ' ')