when /darwin9/
`hwprefs cpu_count`.to_i
when /darwin/
((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
when /linux/
`cat /proc/cpuinfo | grep processor | wc -l`.to_i
when /freebsd/
`sysctl -n hw.ncpu`.to_i
when /mswin|mingw/
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
cpu.to_enum.first.NumberOfCores
#include <windows.h>
#include <stdio.h>
int main()
{
SYSTEM_INFO sysInfo;
OSVERSIONINFOEX osvi;
GetSystemInfo(&sysInfo);
printf("OemId : %u\n", sysInfo.dwOemId);
printf("处理器架构 : %u\n", sysInfo.wProcessorArchitecture);
printf("页面大小 : %u\n", sysInfo.dwPageSize);
printf("应用程序最小地址 : %u\n", sysInfo.lpMinimumApplicationAddress);
printf("应用程序最大地址 : %u\n", sysInfo.lpMaximumApplicationAddress);
printf("处理器掩码 : %u\n", sysInfo.dwActiveProcessorMask);
printf("处理器数量 : %u\n", sysInfo.dwNumberOfProcessors);
printf("处理器类型 : %u\n", sysInfo.dwProcessorType);
printf("虚拟内存分配粒度 : %u\n", sysInfo.dwAllocationGranularity);
printf("处理器级别 : %u\n", sysInfo.wProcessorLevel);
printf("处理器版本 : %u\n", sysInfo.wProcessorRevision);
osvi.dwOSVersionInfoSize=sizeof(osvi);
if (GetVersionEx((LPOSVERSIONINFOW)&osvi))
{
printf("Version : %u.%u\n", osvi.dwMajorVersion, osvi.dwMinorVersion);
printf("Build : %u\n", osvi.dwBuildNumber);
printf("Service Pack: %u.%u\n", osvi.wServicePackMajor, osvi.wServicePackMinor);
}
return 0;
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。