Hanlen
11/15/2019 - 10:26 AM

bash kill a process and its chilldren

#!/bin/bash

list_descendants ()
{
    local children=$(ps -o pid= --ppid "$1")

    for pid in $children
    do
        list_descendants "$pid"
    done

    #echo "${children}"
    echo "$1"
}

kill -9 $(list_descendants $1)