Linux: Check the open files limit for a given process

When you want to find the maximum number of file descriptor you can open, you can use the following:

# ulimit -n
1024

This will return the soft limit i.e. the current limit which can still be increased.

To find out the hard limit i.e. the maximum value you can set, use:

# ulimit -Hn
8192

Now another process than your current shell might have been started with different limits. You can’t give ulimit a process ID to tell you what’s the limit for a different process. But you can read it from /proc/ /limits:

 # cat /proc/13106/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        1024                 unlimited            bytes
Max resident set          7077048320           unlimited            bytes
Max processes             63450                63450                processes
Max open files            4096                 8192                 files
Max locked memory         65536                262144               bytes
Max address space         1572864000           1572864000           bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       63450                63450                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

So if you want to get the soft limit for the other process, do the following:

# grep "Max open files" /proc/13106/limits | awk '{ print $4; }'
4096

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>