aboutsummaryrefslogtreecommitdiff
path: root/etc/child
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-12 13:24:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-12 13:27:07 +0200
commit03d827e2fbc409ef97829f25b8eeca5204f81a3c (patch)
tree6099f0feb9adf3425fba87549b164043e18bd0c7 /etc/child
parent45cddd072119c5abd7ec076cf28d51ee01f125b7 (diff)
downloadxutil-03d827e2fbc409ef97829f25b8eeca5204f81a3c.tar.gz
Re-organize files
Diffstat (limited to 'etc/child')
-rwxr-xr-xetc/child27
1 files changed, 27 insertions, 0 deletions
diff --git a/etc/child b/etc/child
new file mode 100755
index 0000000..32dab60
--- /dev/null
+++ b/etc/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