get number of open files in a process?
Slawa Olhovchenkov
slw at zxy.spb.ru
Thu Jan 21 21:17:26 UTC 2016
On Thu, Jan 21, 2016 at 01:34:18PM +0000, Batutis, Ed wrote:
> Hi,
>
> I need to determine the number of open files in my process - all types of file handles total - sockets, files, everything.
>
> Does this work reliably for that purpose?
>
> int num_open = 0; /* number of open files? */
> kinfo_file *inf = kinfo_getfile(getpid(), &num_open);
> if ( inf ) {
> free(inf);
> }
# limits
Resource limits (current):
cputime infinity secs
filesize infinity kB
datasize 33554432 kB
stacksize 524288 kB
coredumpsize infinity kB
memoryuse infinity kB
memorylocked infinity kB
maxprocesses 8485
openfiles 116442
sbsize infinity bytes
vmemoryuse infinity kB
pseudo-terminals infinity
swapuse infinity kB
# df -ki /dev/fd/
Filesystem 1024-blocks Used Avail Capacity iused ifree %iused Mounted on
fdescfs 1 1 0 100% 4 116439 0% /dev/fd
^^^^^ ^^^^^^
More information about the freebsd-hackers
mailing list