Recent

Author Topic: [SOLVED] How to query the amount of free file handles from the OS?  (Read 1182 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 891
I have the suspicion that my program does not close all files, which it opened, because after 18 days it stops doing it's job without cognizable reason. My program uses a foreign library which might be the causer.

I assume that Linux (in my case Ubuntu Server) can not open an endless amount of file handles at the same time.

Question1: is it possible to query, how many free file handles are currently left in Linux?

Question2: is it possible to query, how many file handles a certain program is currently occupying?

Thanks in advance.
« Last Edit: June 17, 2023, 04:29:44 pm by Hartmut »

zeljko

  • Hero Member
  • *****
  • Posts: 1687
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: How to query the amount of free file handles from the OS?
« Reply #1 on: June 17, 2023, 01:09:11 pm »
Goto /proc/YOURAPPPID and see how many files are open, or use lsof with pid param to see all relevant informations.

Hartmut

  • Hero Member
  • *****
  • Posts: 891
Re: How to query the amount of free file handles from the OS?
« Reply #2 on: June 17, 2023, 04:29:23 pm »
Thanks zeljko for your answer. I found out:

With "ls -l /proc/<PID>/fd" you can get a list of all opened file-handles of a PID.

With "lsof -p <PID>" you also can get a list of all opened file-handles of a PID.

zeljko

  • Hero Member
  • *****
  • Posts: 1687
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: [SOLVED] How to query the amount of free file handles from the OS?
« Reply #3 on: June 17, 2023, 04:39:01 pm »
Also with ulimit you can increase number of opened file descriptors per process if needed

Hartmut

  • Hero Member
  • *****
  • Posts: 891
Re: [SOLVED] How to query the amount of free file handles from the OS?
« Reply #4 on: June 17, 2023, 05:17:47 pm »
Thanks.

 

TinyPortal © 2005-2018