Reputation: 11
I am writing a script that uses "top" command.
When i use top i can see the average CPU USE:
Cpu(s): 41.9%us, 9.4%sy, 0.0%ni, 48.8%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
i know i can press "1" to view each CPU separately:
Cpu0 : 8.8%us, 3.0%sy, 0.0%ni, 85.5%id, 2.6%wa, 0.0%hi, 0.1%si, 0.0%st
Cpu1 : 9.7%us, 3.2%sy, 0.0%ni, 83.6%id, 3.4%wa, 0.0%hi, 0.0%si, 0.0%st
but how can i integrate it into a script when i can't use keypresses?
Upvotes: 0
Views: 565
Reputation: 50034
You can press 'W' to save your current state. That will generate a .toprc
file in your user's home directory it will also mean that the next time you run top as that user all cores will be shown.
It will look something like:
RCfile for "top with windows" # shameless braggin'
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0
Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX
winflags=30009, sortindx=10, maxtasks=0
summclr=1, msgsclr=1, headclr=3, taskclr=1
Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
winflags=62777, sortindx=0, maxtasks=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
winflags=62777, sortindx=13, maxtasks=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX
winflags=62777, sortindx=4, maxtasks=0
summclr=3, msgsclr=3, headclr=2, taskclr=3
You can check out man top
to understand most of this stuff or just screw around in top and 'W' to see what comes out the other end.
Upvotes: 1