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.
Take a look at "top". It gives the total CPU usage and the usage for each process. On my machine, the total DOES NOT match the sum of the various processes. My interpretation is that the CPU usage reported for each process is the average over a certain window. 2 processes, however, will not be using the cpu at the same time, so the total will be less than the sum of the averages.
I don't know of a command to sum up a series of number, but keep in mind that the output of something like ps is rounded--eg all those "0.0"s may really be some finite value.
{ ps aux | gawk ' { print $3 }' | grep -v CPU | sed '2,$ s/$/ +/'; echo p; } | dc
I hope you realize that totaling the values won't give you an accurate total; look at all of the zeros.
Mine probably isn't the best. What it does is removes the column heading first, then adds a + sign to the second thru last lines and feeds it to the dc program, which performs all of the additions. The p tells it to print the result when it's done.
ta0kira
PS If you can get a list with one number per line and only numbers, the underlined part will total it for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.