Skip to content

Instantly share code, notes, and snippets.

@dwelch2344
Created September 12, 2015 15:42
Show Gist options
  • Save dwelch2344/b8b83e08b64de705d61d to your computer and use it in GitHub Desktop.
Save dwelch2344/b8b83e08b64de705d61d to your computer and use it in GitHub Desktop.
Count open file handles for all processes
#!/bin/bash
for D in `find /proc -maxdepth 1 -type d`
do
PID=`echo $D | cut -d'/' -f3 `
if [[ $PID =~ [0-9]+ ]]; then
C=`ps -up $PID | grep $PID | tr -s " " | cut -d " " -f 11-17`
COUNT=`sudo ls -l "$D"/fd | wc -l`
echo " ($PID) $COUNT => $C"
fi
done
@dwelch2344
Copy link
Author

Output looks like (pid) count => cmd

  (29719) 9             => sshd: ec2-user [priv]
  (29722) 13            => sshd: ec2-user@pts/1
  (29723) 5             => -bash
  (29775) 8             => sudo -i
  (29776) 5             => -bash
  (29926) 4             => sh -c cd $RUN_DIR && java $JAVA_FLAGS
  (29927) 114           => java -XX:MaxPermSize=2048M -XX:PermSize=2048M -Xmx2048M -jar latest.war --spring.config.location=settings.properties
  (32070) 8             => top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment