From 6a06676909abd8e900a19138085a7929231f7bf3 Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Sun, 6 Jun 2021 00:54:26 +0200 Subject: Add 'child' utility --- child | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 child (limited to 'child') diff --git a/child b/child new file mode 100755 index 0000000..32dab60 --- /dev/null +++ b/child @@ -0,0 +1,27 @@ +#!/bin/sh + +# child -- print pid of youngest grandchild + +opt= +for x in "$@"; do + case "$x" in + -*) opt="$opt $x"; shift ;; + *) ;; + esac +done + +[ $# -ne 1 ] && { echo usage: $0 [-?] pid 1>&2; exit 1; } + +ps -do pid,etime,comm -k etime $opt | +pid=$1 perl -lane ' + if (/^ *$ENV{pid} / .. 1) { + next if /^ *$ENV{pid} /; + last if not /[|`-]/; + $t = 0; $i = 0; + $t += $_*(60**$i++) for reverse split /:/, $F[1]; + print "$t $_" if $t > 2; + } +' | +sort -n | +head -1 | +cut -d\ -f2 -- cgit v1.2.3