Skip to content

Instantly share code, notes, and snippets.

@yang-wei
Last active January 13, 2021 15:30
Show Gist options
  • Save yang-wei/72ba12a65c93c5021d10f52aa87fefe7 to your computer and use it in GitHub Desktop.
Save yang-wei/72ba12a65c93c5021d10f52aa87fefe7 to your computer and use it in GitHub Desktop.
How to check file descriptors on Linux

system wide

> cat /proc/sys/fs/file-max
13032310

> cat /proc/sys/fs/file-nr
25696   0       13032310

process wide

> cat /proc/3898/limits | grep "open files"
Max open files            1024                 4096                 files

// can also use ulimit
> ulimit -Hn // hard limit         
4096
> ulimit -Sn // soft limit         
1024  

// number of file descriptors in use
ls /proc/3898/fd/ | wc -l
6

Sometimes you tune the parameter per process using sysctl. That is normal because some process are expecting to use more file descriptors.

// conf
[Service]
LimitNOFILE=65536
cat /proc/5054/limits | grep "open files"
Max open files            65536                65536                files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment