How to find number of files opened by my Perl program? Of course, I could use something like
scalar( my @a = glob "/proc/$$/fd/*" );
but it looks a bit hacky... I should have overlooked something very simple.
How to find number of files opened by my Perl program? Of course, I could use something like
scalar( my @a = glob "/proc/$$/fd/*" );
but it looks a bit hacky... I should have overlooked something very simple.
You can scan all possible file handles from 0 to to getrlimit(RLIMIT_NOFILE) using either fstat()
call or fcntl(fd, F_GETFL)
call.
However, using any of these will be significantly slower than simply looking at /proc/self/fd/*
. And, they still depend on some Linux'isms and do not make your program portable.
There is a similar question to that here How to find open global filehandles in a perl program
You will need to change it a bit to suit your requirements
you could use lsof to for that eg. lsof /|wc -l should work fine