<?xml version="1.0" encoding="windows-1252"?>
<node id="350764" title="Open files per process via lsof" created="2004-05-05 09:33:37" updated="2005-07-25 05:53:44">
<type id="1980">
snippet</type>
<author id="29008">
grinder</author>
<data>
<field name="doctext">
</field>
<field name="snippetdesc">
&lt;p&gt;lsof is a tool to LiSt Open Files. It's a handy tool to have when you need to find out why you can't dismount a device, or see if a process is about to exceed its maximum number of allowed file handles. (Here's the [http://freshmeat.net/projects/lsof/|project homepage]).&lt;/p&gt;
&lt;p&gt;But the output is verbose. If you just want the number of open files, and the process name and pid, the following one-liner performs a nice summary.&lt;/p&gt;</field>
<field name="snippetcode">
&lt;CODE&gt;
lsof | perl -lane '$x{"$F[0]:$F[1]"}++;
END { print "$x{$_}\t$_" for sort {$x{$a}&lt;=&gt;$x{$b}} keys %x}'
&lt;/CODE&gt;</field>
</data>
</node>
