Search code examples
cmacosfile-descriptor

Too many open files in system while not actually opening any files


I am developing a backup utility and I am getting the error:

Too many open files in system

after it runs for a while. The error is returned by stat().

Since I am not actually opening any files (fopen()), my question is if any of the following functions (which I am using) take up a file descriptor, and if so, what can I do to release it?

  • getwd()
  • chdir()
  • mkdir()
  • stat()
  • time()

Solution

  • The functions you listed are safe; none of them return anything that you could "close".

    To find out more, run the command lsof -p + PID of your backup process. That will give you a list of files which the process has opened which in turn will give you an idea what is going on.

    See: lsof manual page.