get number of open files in a process?

Mark Martinec Mark.Martinec+freebsd at ijs.si
Fri Jan 22 18:36:38 UTC 2016


On 2016-01-22 00:14, Batutis, Ed wrote:
>> I'm still not convinced the approach here (of checking fds) is the 
>> right one
>> to take - you have to have a very big reserve to not suddenly run out 
>> of fds,
>> one would just limit amount of clients and, well, handle errors as 
>> they can
>> pop up for reasons other than running out of fd slots.
> 
> I have a large reserve - usually more than 1000 fd slots. But
> occasionally something happens and the process runs out. There are a
> lot of different things going on in the process in terms of fd usage.
> So, finding the issue could be easier if I know when the number
> started rising to an unusual level. And I can possibly find the root
> cause more easily if I stop doing some things when this happens. I can
> monitor memory usage and CPU usage easily enough, but I could not
> figure out how to monitor fd usage. There are other approaches, yes.
> But I was looking for something simple but useful until additional
> effort could be expended on other approaches.

I imagine that instrumenting opens, closes, dups and the like
with dtrace would be able to do the job: increment a count
when a new fd pops up, decrement on close, and you may end up
with a diagram of fd usage over time. Or track each operation
dealing with file descriptors individually.

   Msrk


More information about the freebsd-hackers mailing list