forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_signals.sh
executable file
·58 lines (43 loc) · 1.15 KB
/
process_signals.sh
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
#!/usr/bin/perl
# Display signals blocked, ignored and caught by a process
# use as: $0 [PID]...
# based on a script by waldner
# Enhanced by David Bennett - [email protected] - 2015-02-24
use warnings;
use strict;
use bignum;
use Config;
my %sigMap=(
'SigPnd','Thread Pending',
'ShdPnd','Process Pending',
'SigBlk','Blocked',
'SigIgn','Ignored',
'SigCgt','Caught'
);
defined $Config{sig_name} or die "Cannot find signal names in Config";
my @sigs = map { "SIG$_" } split(/ /, $Config{sig_name});
# print the process
sub showproc {
my $pid=shift(@_);
# print BSD style process output
my $pscmd = "ps xww -q $pid";
open (P, "$pscmd |");
while(<P>) { print; }
close P;
# print the signal status
my $statfile = "/proc/$pid/status";
open(S, "<", $statfile) or die "Cannot open status file $statfile";
while(<S>) {
chomp;
if (/^((Sig|Shd)(Pnd|Blk|Ign|Cgt)):\s+(\S+)/) {
if (my @list = grep { oct("0x$4") & (1 << ($_ - 1)) } (1..64) ) {
print "\t$sigMap{$1}: " . join(",", map { "$sigs[$_]" } @list) . "\n";
}
}
}
close(S);
}
# main loop
foreach my $pid (@ARGV) {
showproc($pid);
}