Meaning of FDSize in /proc/PID/status

3

1

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?

Adam Matan

Posted 2009-10-05T09:03:13.567

Reputation: 5 930

Answers

2

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.

Adam Matan

Posted 2009-10-05T09:03:13.567

Reputation: 5 930

1

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?

user4358

Posted 2009-10-05T09:03:13.567

Reputation:

0

from man proc, "* FDSize: Number of file descriptor slots currently allocated.", this is the number of "struct file" in the file descriptor table of a process.

c4f4t0r

Posted 2009-10-05T09:03:13.567

Reputation: 281