#!/usr/bin/env bash
{ set +x; } 2>/dev/null

usage() {
    echo "usage: $(basename $0) pid" 1>&2
    [ "$1" = "-h" ] || [ "$1" = "--help" ]; exit
}

[ "$1" = "-h" ] || [ "$1" = "--help" ] && usage "$@"

[[ $# != 1 ]] && usage

print_childs() {
    local childs=
    childs="$(pgrep -P "$1")"
    [[ -n "$childs" ]] && while IFS= read child; do
        echo "$child"
        print_childs "$child"
    done <<< "$childs";:
}

print_childs "$@"
