Top Command First Iteration Always Returns the Same Result

top command first iteration always returns the same result

CPU utilisation figures are calculated as an average over a time interval. For the first iteration, that time interval is "from system boot until now"; for subsequent iterations, the time interval is "from the last iteration until now".

Linux's top CPU usage - always the same value

I didn't know it's called "iteration", using this keyword I've found a solution for the issue:

top command first iteration always returns the same result

Thank you for your help!

Shell script: top command and date command at once

You can achieve this by piping the output of top through awk, and having awk run date. For example:

top -d 0.5 -n 100 -p myProcessPID \
| awk '/myProcessName/ { system("date +%s"); print $0 }'

You can exert arbitrary control over the format of the output by adjusting the awk program. Note also that you do not need a separate grep, since awk's internal pattern matching serves perfectly well.

How do I get an output from Linux Top in Batch Mode on every iteration?

The problem is because of tail command you use. Try something like this

top -p 310-b -n2 -d 1 | grep -w 310 | awk '{printf "%s,%s,%s,%s\n",$1,$12,$9,$10}'

I use grep -w to filter the lines only containing the info you are interested

How to capture the output of a top command in a file in linux?

for me top -b > test.txt will store all output from top ok even if i break it with ctrl-c. I suggest you dump first, and then grep the resulting file.



Related Topics



Leave a reply



Submit