Question

I am trying to use top to prove that my test process on a Leopardboard (embedded-linux) target has a memory leak. Why does this command

/ # top -b | grep test >> /media/top.txt &

seem to die immediately like this?

[3]+  Stopped (tty output)       top -b | grep test 1>>/media/top.txt

I see that is has produced an empty file

-rwxr-xr-x    1 root     root             0 Jan 15 15:35 top.txt

Top does run in interactive mode producing output like this

 1079     1 root     S    83668 289%  17% test

but I need to record what happens to the memory for this process over a long period of time to file.

Was it helpful?

Solution

Sounds like you have a buggy {top|shell|grep} in that order of likelyhood ;) Lemme guess it's a busybox-based system?

Perhaps a better alternative is to write a simple script to monitor the process' direct stats through the /proc file system. Some entries of interest to you might be

/proc//maps - info about currently mapped memory regions

/proc//smaps - memory consumption for each of the process's mappings

/proc//stat - some useful stats including resident set size (total current memory usage)

The man page proc(5) has much more information about what information is contained within these /proc/ entries.

Happy hunting!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top