检查 Linux 中给定进程的开放 FD 限制 [英] Check the open FD limit for a given process in Linux
问题描述
我最近有一个 Linux 进程泄露"了文件描述符:它打开了它们,但没有正确关闭其中的一些.
I recently had a Linux process which "leaked" file descriptors: It opened them and didn't properly close some of them.
如果我对此进行了监控,我可以提前知道该过程已达到极限.
If I had monitored this, I could tell – in advance – that the process was reaching its limit.
是否有一种不错的 Bash 或 Python 方法来检查 Ubuntu Linux 系统中给定进程的 FD 使用率?
Is there a nice, Bash or Python way to check the FD usage ratio for a given process in a Ubuntu Linux system?
我现在知道如何检查有多少打开的文件描述符了;我只需要知道一个进程允许使用多少个文件描述符.某些系统(如 Amazon EC2)没有 /proc/pid/limits
文件.
I now know how to check how many open file descriptors are there; I only need to know how many file descriptors are allowed for a process. Some systems (like Amazon EC2) don't have the /proc/pid/limits
file.
推荐答案
计算 /proc/
中的条目.应用于进程的硬限制和软限制可以在 /proc/
中找到.
Count the entries in /proc/<pid>/fd/
. The hard and soft limits applying to the process can be found in /proc/<pid>/limits
.
这篇关于检查 Linux 中给定进程的开放 FD 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!