Skip to content

Instantly share code, notes, and snippets.

@patrick0057
Created April 22, 2020 15:44
Show Gist options
  • Save patrick0057/c389eab40c550acd4e8aadc720d6f11e to your computer and use it in GitHub Desktop.
Save patrick0057/c389eab40c550acd4e8aadc720d6f11e to your computer and use it in GitHub Desktop.
Top ten processes consuming file descriptors

Saving a copy of this script here for later use. I found this at the following stackoverflow post.

#!/bin/bash
cd /proc
for pid in [0-9]*
do
    echo "PID = $pid with $(ls /proc/$pid/fd/ | wc -l) file descriptors"
done | sort -rn -k5 | head | while read -r _ _ pid _ fdcount _
do
  command=$(ps -o cmd -p "$pid" -hc)
  printf "pid = %5d with %4d fds: %s\n" "$pid" "$fdcount" "$command"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment