Check number of file descriptors opened by process

To check on the file descriptors opened by process:

lsof -p {PID} | awk '$4 ~ /^[0-9]/ {print $4}' | wc -l

alternately:

ls -1 /proc/{PID}/fd | wc -l

To check all file descriptors opened by a user:

lsof -u {user} | awk '$4 ~ /^[0-9]/ {print $4}' | wc -l

By default the hard and soft limits for a single process are set to 1024 on linux systems. To check on the limits:

ulimit -Hn
ulimit -Sn

To increase edit the "/etc/security/limits.conf" file for corresponding user:

{user} soft nofile 4096
{user} hard nofile 4096

To check if the new limits has been applied type `ulimit -n` after you get a new shell.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

check on limits.conf

su - {USER} -c 'ulimit -Ha' -s /bin/bash

top 10 processes with open files

Listing of top 10 pids and processes showing current open and max open files limit:

# lsof -n 2>/dev/null | awk '$4 ~ /^[0-9]/ {print $1,$2}' | sort | uniq -c | sort -nr | head | while read nr name pid ; do printf "%10d / %-10d %-15s (PID %5s)\n" $nr $(awk '/open files/ {print $5}' /proc/$pid/limits) $name $pid; done

open file limits on daemons

Resource limits in linux can be set in various locations based on the type of requirement.

/etc/security/limits.conf is part of pam_limits and so the limits that are set in this file is read by pam_limits module during login sessions, so pam_limits will not affect the daemon processes.

/etc/sysctl.conf sets the maximum amount of resource that can be used by all users/processes put together via fs.file-max. fs.file-nr gives the current usage and max limit set.

Daemons are started as part of init so pam_limits don't help. ulimit command is used to set the limits of the shell, so is necessary to include ulimit within the initialization script itself like in apachectl startup script. Thus to increase the max open file descriptors from the default of 4096 to 10000, hardcode the below in the startup script itself.

ulimit -n 10000

check process limits

# cat /proc/{PID}/limits

Post new comment

  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.
Comment