Linux List all process with open files

There is a Mobile Optimized version of this page (AMP). Open Mobile Version.

I was having some issues on a server which ultimately lead to some very dire system resource issues, I quickly discovered that the issue was originating due to file locks as multiple processes where accessing and modifying the same files repeatedly all at the same time.

It was quite embarrassing to have created such an issue, but figuring this out was a little complicated as there is no real indication of such unless you run out of nodes or etc which generates an actual server email to warn of such event. If your having some resource or speed issues the ssh command below will list all processes and what files they are accessing, helping you decide whether your bottleneck is file locks or something else.

lsof | perl -lane '$x{"$F[0]:$F[1]"}++;
END { print "$x{$_}\t$_" for sort {$x{$a}<=>$x{$b}} keys %x}'

 

Author: Dean Williams

I'm a Web Developer, Graphics Designer and Gamer, this is my personal site which provides PHP programming advice, hints and tips

Post Tags: