+bin/hog
authorJan Kratochvil <jan@jankratochvil.net>
Tue, 9 Apr 2024 08:19:17 +0000 (16:19 +0800)
committerJan Kratochvil <jan@jankratochvil.net>
Tue, 9 Apr 2024 08:19:17 +0000 (16:19 +0800)
bin/hog [new file with mode: 0755]

diff --git a/bin/hog b/bin/hog
new file mode 100755 (executable)
index 0000000..4dd1017
--- /dev/null
+++ b/bin/hog
@@ -0,0 +1,19 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+my $psu=system($ENV{"HOME"}."/bin/psu")==0;
+local *F;
+open F,"/usr/bin/top -b -n2 -d1|" or die;
+my $top=0;
+while (<F>) {
+  /^top / && $top++;
+  /^$/ && $top++;
+  next if $top!=5;
+  /^(?:\s*\S+){8}\s*(\S+)\s*\S+\s*([^:\s]*):/ or next;
+  next if $1<90;          # CPU %
+  next if $2<($psu?30:1); # minutes it has run
+  tr/'//d;
+  system "DISPLAY=:0 xmessage -timeout 30 -default okay -center '$_' 2>/dev/null";
+  exit 0;
+}
+close F or die;