Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement rlimit() on BSD #809

Closed
NicolasLM opened this issue Apr 23, 2016 · 8 comments · Fixed by #1859
Closed

Implement rlimit() on BSD #809

NicolasLM opened this issue Apr 23, 2016 · 8 comments · Fixed by #1859

Comments

@NicolasLM
Copy link

In most cases a process running out of file descriptors is a sign that the software does not behave correctly. Psutil currently gives the number of fds opened by a process, but not how many can it open.

On Linux this information is available through /proc/<pid>/limits.

This metric per process would be complementary of system wide limits described in #720.

@giampaolo
Copy link
Owner

giampaolo commented Apr 24, 2016

Actually that info is already retrievable via stdlib resource module:

>>> import resource
>>> resource.getrlimit(resource.RLIMIT_NOFILE)
(1024, 4096)

Doing the same via /proc/pid/limits would add the ability to do the same for all processes (instead of just os.getpid()) in case the default value gets modified by a specific process, but I'm not sure how much that's valuable considering it would be linux only.

@NicolasLM
Copy link
Author

I ended implementing something like NicolasLM/sauna@f9a7a52#diff-4cdd796dc1ec5ac72502aab351c123a2R86

It would be surprising if other OSes than Linux do not provide a way to fetch this information as well.

@giampaolo
Copy link
Owner

giampaolo commented Apr 25, 2016

Most (all?) UNIX systems provide a way to know the number of default maximum fds each process can open and #720 is meant to expose that information. /proc/<pid>/limits differs in that it provides the information for any specific process and also returns the updated information in case the user changes the default limits and AFAIK that is only possible on Linux. Other UNIX flavors are able to do the same (provide updated info) only for the current process (via resource module). As such the change you are proposing would be Linux-only.

@NicolasLM
Copy link
Author

I'm pretty sure other platforms provide this information as well, for instance on freebsd procstat -l <pid> gives the rlimits of the process of your choice.

@giampaolo
Copy link
Owner

giampaolo commented Apr 25, 2016

What other platforms are you talking about? Are you sure it's updated info and not the default system setting info being reported insted?

@NicolasLM
Copy link
Author

I just tried on freebsd, indeed it is possible to fetch the actual limits of a process:

$ procstat -l 841
  PID COMM             RLIMIT                  SOFT             HARD      
  841 python2.7        openfiles              14049            14049
>>> import resource 
>>> resource.setrlimit(resource.RLIMIT_NOFILE, (512, 1024))
$ procstat -l 841
  PID COMM             RLIMIT                  SOFT             HARD         
  841 python2.7        openfiles                512             1024     

@giampaolo
Copy link
Owner

giampaolo commented Jun 18, 2016

Getting back to this. Actually I totally forgot it is already possible to do this on Linux:
https://pythonhosted.org/psutil/#psutil.Process.rlimit
Doing the same on FreeBSD would certainly be welcome though. I will try to strace procstat command and try to see what it relies on internally. Linux relies on "man 2 prlimit":
http://linux.die.net/man/2/prlimit
...and that looks like it's Linux only, hence why I am not sure how FreeBSD (or any other UNIX variant) provides this.

@giampaolo giampaolo changed the title Retrieve file descriptor limits per process Implement rlimit() on other platforms != Linux Sep 22, 2016
@giampaolo giampaolo changed the title Implement rlimit() on other platforms != Linux Implement rlimit() on BSD Oct 7, 2016
@giampaolo giampaolo added freebsd and removed linux labels Apr 24, 2017
@giampaolo
Copy link
Owner

@glebius just in case you want to give it a try. ;-)

@giampaolo giampaolo linked a pull request Oct 23, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants