如何取回处理器对C / Linux的有多少? [英] How do I retrieve the number of processors on C / Linux?

查看:83
本文介绍了如何取回处理器对C / Linux的有多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用某些线程处理数据的小C的应用程序。我希望能够知道某个机器上的处理器数量,而不使用系统()&安培;结合到一个小的脚本。

I am writing a small C application that use some threads for processing data. I want to be able to know the number of processors on a certain machine, without using system() & in combination to a small script.

我能想到的唯一的办法就是解析的/ proc内/ cpuinfo 。任何其他有用的建议?

The only way i can think of is to parse /proc/cpuinfo. Any other useful suggestions ?

推荐答案

正如其他评论中所提到的,答案是有用的:

As others have mentioned in comments, this answer is useful:

numCPU = sysconf( _SC_NPROCESSORS_ONLN );

留下一个解决方案,可能会跳过评论人...

Leaving as a solution for folks that might skip over comments...

这篇关于如何取回处理器对C / Linux的有多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆