- 新建一个cpu_num.cpp文件
touch cpu_num.cpp - 写入如下代码
#include<iostream>
#include<unistd.h>
using namespace std;
int main()
{
int cpu_num;
cpu_num = sysconf(_SC_NPROCESSORS_CONF);
cout<<"cpu_num="<<cpu_num<<endl;
return 0;
}
- 编译成可执行程序
g++ -o cpu_num cpu_num.cpp - 执行程序,得到结果
./cpu_num