I am trying to get a list of open files per process. I ran the following one-liner from PerlMonks:
lsof | perl -lane '$x{"$F[0]:$F[1]"}++;
END { print "$x{$_}\t$_" for sort {$x{$a}<=>$x{$b}} keys %x}'
It returns the total count of open files, and the process name and pid. The result is sorted in ascending order, and the last line is as follows:
1065702 java:15437
So when I run lsof -p 15437
, I would expect it to return the same number, however I'm getting:
$ lsof -p 15437 | wc -l
403
Why the discrepancy?
Addendum
A third source of discrepancy:
$ cd /proc/15437/fd
$ ls -1 | wc -l
216