Skip to content

Instantly share code, notes, and snippets.

@jesuscast
Created March 18, 2016 06:11
Show Gist options
  • Select an option

  • Save jesuscast/f8e752032186f24b8fa9 to your computer and use it in GitHub Desktop.

Select an option

Save jesuscast/f8e752032186f24b8fa9 to your computer and use it in GitHub Desktop.
Finds the id of the process that has the most open files.
HIGHEST_PROCESS=''
HIGHEST_PROCESS_FILES=0
ps aux | awk 'NR > 1' | awk '{ print $2 }' > tmp.txt
while read -r process_element; do
process_pid="$process_element"
number_of_files=`lsof -p $process_pid | wc -l | awk '{ print $1 }'`
if [ $number_of_files -gt $HIGHEST_PROCESS_FILES ]; then
HIGHEST_PROCESS=$process_pid
HIGHEST_PROCESS_FILES=$number_of_files
fi
done < 'tmp.txt'
rm 'tmp.txt'
echo "pid with most open files $HIGHEST_PROCESS"
echo "number of open files $HIGHEST_PROCESS_FILES"
echo "information `ps -p $HIGHEST_PROCESS | awk 'NR > 1'`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment