-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackmon.pl
More file actions
executable file
·88 lines (72 loc) · 1.66 KB
/
stackmon.pl
File metadata and controls
executable file
·88 lines (72 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/bin/perl
# $Header:$
use strict;
use warnings;
use File::Basename;
use FileHandle;
use Getopt::Long;
use IO::File;
use POSIX;
#######################################################################
# Command line switches. #
#######################################################################
my %opts = (
sleep => 5,
);
sub main
{
Getopt::Long::Configure('require_order');
Getopt::Long::Configure('no_ignore_case');
usage() unless GetOptions(\%opts,
'a',
'help',
'sleep=s',
);
usage() if $opts{help};
while (1) {
print "\n";
print strftime("%Y%m%d %H:%M:%S\n", localtime());
foreach my $f (glob("/proc/*/stack")) {
next if $f =~ /\/self\//;
$f =~ /\/([0-9]*)\//;
my $pid = $1;
next if $pid == $$;
my $fh = new FileHandle($f);
next if !$fh;
my $s = '';
while (<$fh>) {
$s .= $_;
}
if (!$opts{a}) {
next if $s =~ /do_signal_stop/;
next if $s =~ /poll_schedule_timeout/;
next if $s =~ /n_tty_read/;
next if $s =~ /do_wait/;
next if $s =~ /pipe_wait/;
}
my $cmd = 'unknown';
$fh = new FileHandle("/proc/$pid/cmdline");
$cmd = <$fh> if $fh;
$cmd =~ s/\0/ /g;
print "$cmd:\n";
print $s;
}
sleep(5);
}
}
#######################################################################
# Print out command line usage. #
#######################################################################
sub usage
{
print <<EOF;
stackmon.pl -- list out stacks of processes.
Usage: stackmon.pl
Switches:
-a Show all procs - otherwise we will filter the boring ones.
-sleep N Pause for N seconds before refresh. Default $opts{sleep}
EOF
exit(1);
}
main();
0;