What's the difference between `lsof -p <pid> | wc -l` and `ls /proc/<pid>/fd | wc -l`?
lsof
will also give you memory mapped .so-files - which technically isn't the same as a file handle the application has control over. /proc/<pid>/fd
is the measuring point for open file descriptors - however: Mentioned in the proc-man page - if the main thread of a multithreaded program has terminated, this directory will be unavailable.
lsof -p <pid> | grep -v mem | egrep -v '^COMMAND PID' | wc -l
will show you the same items as ls /proc/<pid>/fd | wc -l
.
The memory maps is available in /proc/<pid>/maps
.