LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-30-2005, 01:33 AM   #1
Philip_38
LQ Newbie
 
Registered: Jan 2005
Location: Florida
Distribution: red hat 9.0
Posts: 2

Rep: Reputation: 0
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
 
Old 01-30-2005, 08:49 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 01-30-2005, 08:58 AM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 01-30-2005, 09:24 AM   #4
Philip_38
LQ Newbie
 
Registered: Jan 2005
Location: Florida
Distribution: red hat 9.0
Posts: 2

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C Library for lsof loki.guz_BR Linux - Security 2 01-08-2021 01:06 AM
What to do when lsof fails.... SpacedCowboy Linux - Security 2 10-29-2005 02:39 PM
lsof and fuser do not work with /dev/dsp alexrait1 Slackware 4 10-09-2004 04:07 PM
lsof can't identify protocol sock rozeboom Linux - Networking 4 05-21-2004 12:34 PM
lsof: command not found ionian2k Linux - Newbie 1 12-26-2002 08:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration