ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So, at index cpus[39] the idle value is: 99.5%
That's correct.
But once in awhile the out put of "top -n 1" returns different output:
15:12:35 up 52 min, 3 users, load average: 0.29, 0.17, 0.09
83 processes: 81 sleeping, 1 running, 1 zombie, 0 stopped
CPU states: cpu user nice system irq softirq iowait idle
total 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 100.0%
cpu00 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 100.0%
cpu01 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 100.0%
cpu02 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 100.0%
cpu03 0.0% 0.0% 0.0% 0.0% 0.0% 0.0% 100.0%
This output is missing Time like the one. So, that shifted the position of cpu idle. Therefore, at cpus[39], the value is cpu00, instead of 100.0%
[/B]Is there any command that can retrieve cpu's total idle time better than "top -n 1"[/B]
Then it's more reliably the same element (and easier to count!). My "top" output differs, but yours should be $cpus[8]. You can use $(...) instead of `...`.
Hi
thank you for your response.
That helps alot, and I also have other solution:
let freeMB=`free -m | tail -2 | head -1 | awk '{print $4}'`
cpus=`top -n 1| head -4 | tail -1 | awk '{print $8}'`
echo $freeMB
echo ${cpus}
But I have a java program waiting to catch freeMB's and cpus' value. However, only freeMB's value is captured, and cpus' value isn't.
is there a problem with stdin?
thank you for replying..
yes it works..
but now i run into a problem with java and linux...
java is waiting for my script to echo back with cpu's and freeMem's value....however, only freeMem's is caught..
looks like tty is lost..any suggestion?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.