Calculate CPU load limit on GNU/Linux

echo "$(( $(( $(grep 'physical id' '/proc/cpuinfo' | uniq | wc -l) * $(grep 'core id' '/proc/cpuinfo' | wc -l) )) * 2 + 1 ))"
shell order of operation example which calculates: x = number of physical CPU's y = number of cores per CPU 2(x * y) + 1 = CPU load limit
Sample Output

By: snorf
2015-11-14 20:44:39

What Others Think

Hmm... You can simplify the command a bit. You don't need grep AND wc in the second part, grep -c (count) will do: grep -c 'core id' '/proc/cpuinfo' You can drop the nested bash maths $(( $(( x * y )) * 2 + 1)) $(( x * y * 2 + 1)) Also, if you want, you can drop all the unnecessary quotes, leaving: echo $(( $(grep 'physical id' /proc/cpuinfo | uniq | wc -l) * $(grep -c 'core id' /proc/cpuinfo) * 2 + 1 )) . What I don't understand it what you're actually calculating. My laptop has one die, two cores (hyperthreaded): that's 4 (virtual processors). The command tells me "9". What should I do with this number?
flatcap · 258 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: