1

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.

Dallaylaen
  • 5,268
  • 20
  • 34

3 Answers3

1

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.

mvp
  • 111,019
  • 13
  • 122
  • 148
0

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

Community
  • 1
  • 1
Ahmad
  • 12,336
  • 6
  • 48
  • 88
-1

you could use lsof to for that eg. lsof /|wc -l should work fine

Saddam Abu Ghaida
  • 6,381
  • 2
  • 22
  • 29
  • AFAIK `lsof` uses /proc/*/fd internally, so it's generally the same... Oh and I need files open by _this_ process, not everyone else. – Dallaylaen Nov 10 '12 at 07:36