我希望使用kthread_create()/kthread_bind()函数启动一个内核线程来执行每个CPU的任务。不过,我无法查询可用CPU数量。我查阅了CPU_SET手册页,但没有找到有用信息。
请问您是否有其他想法?
请问您是否有其他想法?
你可以使用x86info。它不是默认安装的(sudo apt-get install x86info (ubuntu))
x86info | grep Found
Found 2 CPUs
另一种方法是:
grep processor /proc/cpuinfo | wc -l
2
这就是你在寻找的吗?
如果您使用的是 Fedora Linux / RHEL / CentOS v6+ / Debian Linux v6+ 系统,您可以使用 lscpu
命令:
michael@test:~$ lscpu
Architecture: i686
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 37
Stepping: 5
CPU MHz: 1199.000
BogoMIPS: 5319.88
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
-p
选项感兴趣,它可以给你可解析的输出:michael@test:~$ lscpu -p
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
# starting from zero.
# CPU,Core,Socket,Node,,L1d,L1i,L2,L3
0,0,0,,,0,0,0,0
1,0,0,,,0,0,0,0
2,1,0,,,1,1,1,0
3,1,0,,,1,1,1,0
$ nproc --all
4
--all 打印已安装处理器的数量