I’ve recently had to deal with a process leaking file descriptors. The following command came in handy as a quick way to count how many file descriptors a process is using.

Let’s say that we want to count them for the process(es) called firefox:

ps -ae | grep firefox | perl -lane 'print $F[0]' | while read filename; do ls /proc/$filename/fd; done | wc -w

TADAA!