Open desc. count by app and faster method to discover used count than lsof?

Any clever command to discover current open descriptor count usage per app, or display lets say top3 top apps and its desc. count? Any faster method to display total count than lsof|wc -l which takes quarter hour for million lines?

And the file to modify on Arch Linux is:

grep nofile /etc/security/limits.conf
# - nofile - max number of 0pen file descript0rs
* hard nofile 4000000


Hi Postcd,

You could make use of the /proc filesystem, which will be lightning fast. You can do something like this:

# for PROC in $(ls /proc/ | grep -E '[0-9]') ; do echo "$(ls /proc/"$PROC"/fd/ | wc -l) FD for PID $PROC ($(ps -p $PROC -o comm=))" ; done | sort -g | tail -3

On my current machine I get these results:

ls: cannot access '/proc/25710/fd/': No such file or directory
ls: cannot access '/proc/25711/fd/': No such file or directory
ls: cannot access '/proc/25712/fd/': No such file or directory
126 FD for PID 289 (systemd-journal)
170 FD for PID 3203 (firefox)
185 FD for PID 1 (systemd)

It should throw some errors, since processes appear and end while the data goes through the iteration and the pipes, but after some testing on various systems the slowest run was 3s. You’ll need to run it as root to be able to access file descriptors of all processes.

The above command displays the top 3 process, you can adjust it by modifying the argument of the last tail. For example, if you need the top 10, you can change the last part to tail -10. If you need a full listing of every process, you can omit the | tail -3 part altogether.

thanks for the awesome information.