Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to find out the open FD limit under Ubuntu machines which doesn't have the /proc/PID/limits, namely EC2 machines.

I have been looking into /proc/PID/limits, and found the the entry FDSize with values like:

FDSize: 256
FDSize: 512

Any way I can deduce the maximum allowed open file descriptors from this value?

Thanks,

Udi

share|improve this question
add comment

2 Answers

Afaik, on Linux the per-process limit of open files is controlled via the ulimit command. From man ulimit:

NAME
    ulimit - set or report file size limit

DESCRIPTION
    The  ulimit utility shall set or report the file-size writing limit 
imposed on files written by the shell and its child processes (files 
of any size may be read). Only a process with appropriate privileges 
can increase the limit.

On my system:

$ ulimit -aS | grep "open files"
open files                      (-n) 1024

$ ulimit -aH | grep "open files"
open files                      (-n) 1024

The system-wide limit is stored in /proc/sys/fs/file-max

$ cat /proc/sys/fs/file-max
305018

The The Linux HTTP Benchmarking section on tuning file descriptor limits on Linux has more info.

I'm not entirely clear if this is exactly what you were looking for. Does this answer your question?

share|improve this answer
add comment
up vote 2 down vote accepted

No, it does not show the limit - just the usage.

>>> import resource
>>> resource.setrlimit(resource.RLIMIT_NOFILE, (10000, 10000))
>>> resource.getrlimit(resource.RLIMIT_NOFILE)
(10000, 10000)

Now:

>>> for i in range(5000):
...     f=open('/tmp/delme'+str(i),'w')
...     fs.append(f)

And:

laptop:/proc/20160$ cat status
...
FDSize: 8192
...

The value wasn't changed after changing the limit, just after creating the files. It means that it measures the actual usage, not the limits.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.