Ubuntu – lsof runs REALLY slow when Chromium or Firefox is open

lsofUbuntu

I have a little script that runs lsof on my laptop (Ubuntu Natty) every now and then to check for a few things. I recently noticed that it runs really slowly when I have Chromium or Firefox open.

Without Chromium open:

$ lsof | wc -l
5288

With:

$ lsof | wc -l
5721

Without:

$ time lsof > /dev/null

real    0m0.134s
user    0m0.080s
sys     0m0.040s

With:

$ time lsof > /dev/null 
real    0m20.250s
user    0m0.080s
sys     0m0.070s

lsof seems to get "stuck" when looking at the browser's entries.

I'm just curious why it's happening, and if there's a way around it. Suggestions?

Best Answer

Try the -n option:

-n This option inhibits the conversion of network numbers to host names for network files. Inhibiting conversion may make lsof run faster. It is also useful when host name lookup is not working properly.