LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Identify program memory usage from command line (http://www.linuxquestions.org/questions/linux-software-2/identify-program-memory-usage-from-command-line-625623/)

MikeyCarter 03-04-2008 09:42 AM

Identify program memory usage from command line
 
Me again with memory questions.

I have one or many programs that run periodically which have a high demand for memory.

They start up... through a large portion to swap, then finish up and release their memory. Then the 200K-800K or so is filled up with disk cache, and slowly over the day swaps in the 200K-800K.

I want to identify which programs they are. Is there a command line tool, which I can dump the output to log file, that will report the rough memory usage of a program?

Tinkster 03-04-2008 12:16 PM

top -b -n 1 and a for loop ... for instance to capture
roughly an hour
Code:

for z in `seq 1 3600`; do top -b -d 1 -n 1| awk -f top.awk;sleep 1; done | tee topoutput
where top.awk looks something like this (here it would give you the
top-20 memory hogs per run - see head):
Code:

BEGIN{
  command = "LC_ALL=C sort -k 10,10gr|head -20"
}
{
  line[NR]=$0
  last=NR
}
END{
  for(i=1;i<8;i++){
    print line[i]
  }
  for(i=8;i<last;i++){
    print line[i]|& command
  }
  close(command, "to")
  while ((command |& getline out) > 0)
    print out
  close(command)
}


Cheers,
Tink


All times are GMT -5. The time now is 08:39 PM.