commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
There are 3 alternatives - vote for the best!
Using the output of 'ps' to determine CPU usage is misleading, as the CPU column in 'ps' shows CPU usage per process over the entire lifetime of the process. In order to get *current* CPU usage (without scraping a top screen) you need to pull some numbers from /proc/stat. Here, we take two readings, once second apart, determine how much IDLE time was spent across all CPUs, divide by the number of CPUs, and then subtract from 100 to get non-idle time.
If you can do better, submit your command here.
You must be signed in to comment.