Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am logging the output of: top -b -n1 -c so I can keep track of which processes are using how much memory and CPU each minute. When top shows the full command line (-c), the command line text gets truncated at the edge of the screen. This is perfect when running and displaying in a terminal. However, I am sending STDOUT to a file for parsing later and want the full command name logged. Is there a way I can tell top to use a specific screen width? (I know it maxes at 512, that would be fine)

Is there a better way to achieve a similar goal: get periodic stats about which processes are running and how many resources they are consuming?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

This seems to work:

COLUMNS=512 top -b -n1 -c

That appears to pad the lines with spaces to 512 columns, though, at least when the output is piped to another program, so you may want to filter the output like this:

COLUMNS=512 top -b -n1 -c | sed 's/  *$//'

where that asterisk is preceded by two space characters.

share|improve this answer
add comment

I guess top wasn't really intended to be used this way and you should use ps instead.

$ ps axv
PID TTY      STAT   TIME  MAJFL   TRS   DRS   RSS %MEM COMMAND
   1 ?        Ss     0:07    314    31  3908    24  0.0 init [3]  
   2 ?        S      0:00      0     0     0     0  0.0 [kthreadd]
   3 ?        S      0:06      0     0     0     0  0.0 [ksoftirqd/0]
   4 ?        S      0:12      0     0     0     0  0.0 [migration/0]
   5 ?        S      0:10      0     0     0     0  0.0 [migration/1]
   6 ?        S      0:05      0     0     0     0  0.0 [ksoftirqd/1]
....

See man 1 ps for the long list of options.

share|improve this answer
    
This may be a smart direction to head in the future. Thanks –  Zach Dwiel Oct 14 '10 at 18:26
    
The advantage of top is that it does show other data related to overall CPU load. I'm using this to log what else is taking up CPU time when a slow request is detected on my web server: I care about the load at that instant, and ps doesn't show that very well. –  Matthew Schinckel Sep 5 '12 at 2:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.