As a Developer, I want to provide a tool for sysadmins to determine how many files are open in the system. This is useful when combined with the information about resource limits (or ulimit
) for processes. The lsof
utility lists different types of open files, e.g. regular files and txt
files. I have read the lsof
source code extensively and would really like to know the following:
1.) Which open file descriptor types are counted by the kernel as part of the resource limit imposed on maximum open files. In other words: which file types as reported by lsof
are counted in the open file statistics, such that opening more of them after reaching the resource limit would result in an error.
1.1.) Are txt
files counted for the ulimit/resource limit?
2.) I don't quite understand what txt
files are exactly. The manual says "program code and data", but what data exactly? I see things like:
ULimitTes 20517 federico txt (...) /System/Library/Fonts/Apple Color Emoji.ttc
being reported as a txt
file. If I, however, open a file within a dynamic library (with fopen
), that is then linked into a program and run, that file is reported with a corresponding file descriptor on lsof
, e.g.:
ULimitTes 20517 federico 6r REG (...) /Users/federico/INPUT
I expected that file to be a txt
file, given that it wasn't opened by the program itself but by a library used by the program. Any hints to further clarify the nature of txt
files would be appreciated!
3.) If I setrlimit(RLIMIT_NPROC)
to 2 in a program but attempt to open 3 files with fopen
, this succeeds. I would have expected the third file open operation to fail, as the limit was set to 2. So what does the limit set by setrlimit(RLIMIT_NPROC)
(and then verified by querying getrlimit(RLIMIT_NPROC)
) do?
Many thanks in advance for any hints on this! :-)