LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Lsof Is Useless?? (https://www.linuxquestions.org/questions/linux-software-2/lsof-is-useless-283959/)

Philip_38 01-30-2005 01:33 AM

Lsof Is Useless??
 
I have a question that it might seem too simple. Nevertheless, here it goes:

My linux machine is rendered useless because my apps complain: to many files open. I use red hat 9.0

Using lsof or any othe tool, how can I get summary vision, not the list of each open file, of the amount of files that each process has open? I need something like:



Name #files

Proc1 99

Proc2 2000



Etc.


Is it possible to get a picture like that from vanilla lsof? Don't we agree that whever wrote that utility is an idiot? Am I the only engineer who sees this issue in this manner?

Philip

Matir 01-30-2005 08:49 AM

I don't think that whoever wrote that tool is an idiot. I think that it does what it was designed to do very well.

If you really want just a count of the file descriptors open by each process, you can just spider the /proc directory and extract the data from there.

To suggest someone is an idiot just because they didn't write a program to your needs seems a bit harsh.

Matir 01-30-2005 08:58 AM

And if all you really want is what you mentioned above, a list of pids and the number of file descriptors they have in use, try this:
Code:

#!/bin/bash
PIDS=`echo /proc/[0-9]* | sed 's/\/proc\///g' | sed 's/ /\n/g' | sort -n`
for i in $PIDS
        do if [ -d "/proc/$i/" ]
        then    echo -n "$i: "
                ls /proc/$i/fd/ | wc -w 2>/dev/null
        fi
done

I just whipped this up on the fly, so there may be a bug or two, but I'm sure you get the idea.

Philip_38 01-30-2005 09:24 AM

Files per process
 
Thanks for the script, it helps.

The question is: how do I include the command name? Also, many processes are created by others, in my case the Asterisk PBX spawns many subprocesses. Is there a way to do a grouping on the first 5 letters of the command name, instead of the process number?

I know my questions are too simple for a real linux expert. I appreciate your help. These are basic debugging techniques, and the world deserves to have access to them.


All times are GMT -5. The time now is 03:48 PM.