I am running few java processes on a machine and I wanted an exact count of number of open files and what kind those files.
First of all, running
sudo lsof takes a long time.
[user@host]:~$ time sudo lsof > lsof.txt real 1m5.920s user 0m27.152s sys 0m38.100s
Finding out the number of files opened by java processes:
[user@host]:~$ grep -e "^java" lsof.txt -c 2565341
which is unusually high.
If I try to arrive at the same number by filtering
lsof's output using
-c flag, I get a totally different answer and
lsof takes very little time compared to the first command
[user@host]:~$ time sudo lsof -c java | wc -l 4465 real 0m0.139s user 0m0.052s sys 0m0.068s