Skip to content

Instantly share code, notes, and snippets.

@mttjohnson
Last active February 25, 2020 10:04
Show Gist options
  • Save mttjohnson/59df8359b53454ebdfbf315639ca4fd6 to your computer and use it in GitHub Desktop.
Save mttjohnson/59df8359b53454ebdfbf315639ca4fd6 to your computer and use it in GitHub Desktop.
View system open file limits (nofile) and how many file in use by user
# View system limit configurations
cat /etc/security/limits.conf
# There may be overrides to limits in limits.d
cat /etc/security/limits.d/90-nproc.conf
# find active number of file descriptors per user
ps -A x | grep [w]ww-prod | awk '{print $1}' | xargs -I '{}' ls /proc/{}/fd | wc -l
# Alternate count of file decriptors
lsof -u www-prod | grep ' REG\|FIFO\|unix ' | grep -v ' mem REG ' | grep -v ' txt REG ' | grep -v ' DEL REG ' | wc -l
# Listing file descriptors for an individual process
lsof -p 49122 | grep ' REG\|FIFO\|unix ' | grep -v ' mem REG ' | grep -v ' txt REG ' | grep -v ' DEL REG '
ls -lA /proc/49122/fd
# the nproc limit includes the number of threads for the user, not just processes
# Get summary of count of processes and threads by user
ps h -Led -o user | sort | uniq -c | sort -n
# count total number of processes/threads used per user
ps h -Lfu www-prod | wc -l
# Get summary of processes for a user with a column indicating the number of threads each process has running
ps -o nlwp,pid,lwp,args -u www-prod | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment