Linux – How to know how many files a process opened efficiently

fileslinuxlsof

I knows I can use the command

lsof -p xxxx | wc -l

to know the count of opened files op a process, it works, but however, it is just too inefficient. I have some server process which have too many socket files, the wc -l method never return the result. So, what is the efficient way to know how many files opened on a process?

Thanks.

Best Answer

There is a proc interface for open files: /proc/PID/fd/. It is a directory of symlinks. Any open sockets will appear to be linked to a file named "socket:[INODE NUMBER]"