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
Gdb: Lx-Symbols Undefined Command
Can Any One Say How to Install the Slack in Ubuntu14.04 and While Trying This Was the Error
Block Device Information Without Mounting in Linux
Intellij Idea 2017.2 Can't Add Openjk 9 on Linux Mint 18
Linux/Module.H No Such File or Directory
Perl Fork() Exec() , Child Process Gone Wild
Some Details on Arm Linux Boot
Tomcat6 -> How to Put a Project into the Root Folder
Combine Results of Column One Then Sum Column 2 to List Total for Each Entry in Column One
How to Compare 2 Lists of Ranges in Bash
How to Execute Multiple Commands After Sudo Command
Best Approach to Detecting a Move or Rename to a File in Linux
How to Search for Invisible Control Characters
How to Use Find -Exec in Cmake Execute_Process
Why Is Execution Time of a Process Shorter When Another Process Shares the Same Ht Core
How to Mount Google Bucket as Local Disk on Linux Instance with Full Access Rights
How to Fetch the Tags for Ec2-Describe-Instances in a Shell Script