Linux – lsof runs very slow in the server

linuxlsof

I'm running lsof in one of my Linux server to check if one file (/tmp/incoming_data.txt) in the ext3 system is opened by other programs. My server has lots of TCP connection on it. The weird thing is the execution of 'sudo lsof' takes about two minutes to finish and it uses 99.x% CPU during that two minutes.

The command I used is sudo lsof /tmp/incoming_data.txt. I've tried "fuser" which takes about the same amount CPU and execution time. Is there anything I can do fix this problem?

Best Answer

If you are certain that you can skip the open TCP or UDP connections, since you mentioned there are too many of them, you can use the dialect-specific option of lsof -X.

lsof -X

Read the man page of lsof and search for '-X' for detailed information.