diff options
author | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-06 00:54:26 +0200 |
---|---|---|
committer | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-06-06 00:54:26 +0200 |
commit | 6a06676909abd8e900a19138085a7929231f7bf3 (patch) | |
tree | 155feb1b94a3dc0d60cc63b734c4a168a38e0f85 /child | |
parent | e6c3d682542b5544f15db0b58ff2b018c96dbf5d (diff) | |
download | xutil-6a06676909abd8e900a19138085a7929231f7bf3.tar.gz |
Add 'child' utility
Diffstat (limited to 'child')
-rwxr-xr-x | child | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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 |