Detect number of IDLE processors ruby

Posted by Yannick Wurm on Stack Overflow See other posts from Stack Overflow or by Yannick Wurm
Published on 2010-04-12T18:29:26Z Indexed on 2010/04/12 18:33 UTC
Read the original article Hit count: 414

Filed under:
|
|

Hello, I work on shared linux machines with between 4 and 24 cores. To make best use of them, I use the following code to detect the number of processors from my ruby scripts:

return `cat /proc/cpuinfo | grep processor | wc -l`.to_i

(perhaps there is a pure-ruby way of doing this?)

But sometimes a colleague is using six or eight of the 24 cores. (as seen via top). How can I get an estimate of the number of currently unused processors that I can use without making anyone upset?

Thanks!

© Stack Overflow or respective owner

Related posts about ruby

Related posts about unix