new perls v5.39.10
[andk-cpan-tools.git] / bin / smoker-ids.pl
blob8d7a7c7ad9e88c509feae75a7d10722334e60f31
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
11 =head1 SYNOPSIS
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--help|h!>
25 This help
27 =back
29 =head1 DESCRIPTION
31 We send all sand processes a SIGSTOP when one of our precious files
32 gets lost in the hope that the frozen jobs give us a clue about who
33 was doing what when the files got lost.
35 =cut
38 use FindBin;
39 use lib "$FindBin::Bin/../lib";
40 BEGIN {
41 push @INC, qw( );
44 use Dumpvalue;
45 use File::Basename qw(dirname);
46 use File::Path qw(mkpath);
47 use File::Spec;
48 use File::Temp;
49 use Getopt::Long;
50 use Pod::Usage;
51 use Hash::Util qw(lock_keys);
53 our %Opt;
54 lock_keys %Opt, map { /([^=|!]+)/ } @opt;
55 GetOptions(\%Opt,
56 @opt,
57 ) or pod2usage(1);
58 if ($Opt{help}) {
59 pod2usage(0);
62 use POSIX qw(strftime);
64 our @PRECIOUS = qw(
65 /home/sand/.zshrc
66 /home/sand/.zhistory
67 /home/sand/.cpanreporter/config.ini
68 /home/sand/.cpanreporter/metabase_id.json
71 PEACEFUL: while () {
72 for my $f (@PRECIOUS) {
73 unless (-e $f) {
74 my $localtime = localtime;
75 warn "ALERT $localtime: missing file '$f', going to stop all sand/perl programs";
76 last PEACEFUL;
79 sleep 2;
82 open my $fh, "-|", ps => "auxww" or die;
83 while (<$fh>) {
84 my($user,$pid,undef,undef,undef,undef,undef,undef,undef,undef,$cmd) = split " ", $_, 11;
85 next unless $user eq "sand";
86 next if $pid == $$;
87 next unless $cmd =~ /perl/;
88 open my $fh2, "<", "/proc/$pid/status" or next;
89 while (<$fh2>) {
90 # VmData: 7528 kB
91 next unless /^VmData:(?:\s+)(\d+) kB/;
92 printf "%s %5d %7d: %s\n", strftime("%FT%T",localtime), $pid, $1, $cmd;
94 warn "Stopping now $pid\n";
95 kill STOP => $pid or die "Could not stop: $!";;
100 # Local Variables:
101 # mode: cperl
102 # cperl-indent-level: 4
103 # End: