From be555f29f47f81993c12bf76065a0cb6bb0fee96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20W=C3=BChrer?= Date: Thu, 3 Nov 2022 19:23:18 +0100 Subject: Add a few old things. --- pf | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 pf (limited to 'pf') diff --git a/pf b/pf new file mode 100755 index 0000000..95c8e92 --- /dev/null +++ b/pf @@ -0,0 +1,38 @@ +#!/bin/bash + +set -ue + +get_parent () { + ps hoppid p$1 +} + +get_children () { + ps hopid --ppid "$1" +} + +get_ancestors () { + case $1 in + 1|'') : + ;; *) get_ancestors $(get_parent $1) + esac + echo "$1" +} + +get_descendents () { + for c in $(get_children "$1") + do echo "$c" + get_descendents "$c" + done +} + +declare -i p +for p in "$@" +do + [[ $p -ne 0 ]] && { + get_ancestors "$p" + get_descendents "$p" + } | { + readarray -t pids + ps -Hf "${pids[@]}" | sed "/^[^ ]* *$p /s/.*/&/" + } +done -- cgit v1.2.3