Last active
August 29, 2015 14:23
-
-
Save p120ph37/671586ec76d77724b6f5 to your computer and use it in GitHub Desktop.
Cross-reference `/proc/locks` against a particular file to show what locks are present against that file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
my %pl; | |
open(my $fh, '<', '/proc/locks') or die $!; | |
for(<$fh>) { | |
my @f = split /\s+/; | |
push(@{$pl{$f[5]}}, \@f); | |
} | |
close($fh); | |
for(@ARGV) { | |
my @s = stat or warn "$!: $_\n" and next; | |
my $i = sprintf("%2x:%2x:%d", $s[0]>>8, $s[0]&0xFF, $s[1]); | |
print("File: $_\tInode: $i\n"); | |
print(" No locks.\n") unless $pl{$i}; | |
print(" Region $_->[6]-$_->[7] locked for $_->[3] by PID $_->[4] with a $_->[1] $_->[2] lock.\n") for @{$pl{$i}}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/proc/locks
(On CentOS 6,/proc/locks
is world-readable).stat()
on the files (r+x access to the containing dir).Example usage: