#!/bin/sh - # # Oliver Fromme # # BSD-style copyright and standard disclaimer applies. # # Prints recursively all children processes of a given PID, # including the given PID itself. If no PID is specified, # it starts at your shell's PID. Output is not sorted. # # Note: If a process has been "daemonized" or otherwise # detached from its parent process, then its parent process # is init (PID 1), and this script will not find it. # Usage() { echo "Usage: ${0##*/} [pid]" >&2 exit 1 } if [ $# -lt 1 ]; then set -- `ps -lp $$ | awk '!/PID/{print $3}'` else for i in "$@"; do case "$i" in ""|*[!0-9]*) Usage ;; esac done fi ps -alx | awk ' function f(s, _a) { split(s, _a) for(i in _a) { print _a[i] f(c[_a[i]]) } } { if ($2 != $3) c[$3] = c[$3] " " $2 } END { f("'"$*"'") } ' #--