MacOS
Code
获取系统版本
关于MacOS更多系统版本号,可参照Post not found: Xcode与MacOS版本对应 Xcode与MacOS版本对应
1 2 3 4 5 6 7 8 9 10 11 12 13 char * getSystemInfo () { char buf[1024 ]; unsigned buflen = 0 ; char line[256 ]; FILE *sw_vers = popen ("sw_vers" , "r" ); while (fgets (line, sizeof (line), sw_vers) != NULL ) { int l = snprintf (buf + buflen, sizeof (buf) - buflen, "%s" , line); buflen += l; assert (buflen < sizeof (buf)); } pclose (sw_vers); return buf; }
输出:1 2 3 ProductName: macOS ProductVersion: 11.2 .1 BuildVersion: 20 D75
硬件信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 $ system_profiler SPHardwareDataType > >> Hardware: Hardware Overview: Model Name: Mac mini Model Identifier: Macmini7,1 Processor Name: Dual-Core Intel Core i5 Processor Speed: 2.6 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 3 MB Hyper-Threading Technology: Enabled Memory: 8 GB System Firmware Version: 430.0.0.0.0 SMC Version (system): 2.24f32 Serial Number (system): C07QD03YG1HW Hardware UUID: 1545EB61-968C-52E4-849F-5DE1AAD2DE35 Provisioning UDID: 1545EB61-968C-52E4-849F-5DE1AAD2DE35
CPU品牌
1 2 3 $ sysctl machdep.cpu.brand_string > >> machdep.cpu.brand_string: Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz
系统版本
1 2 3 4 $ sw_vers ProductName: macOS ProductVersion: 11.2.1 BuildVersion: 20D75
Linux
Code
获取系统版本
1 2 3 4 5 6 7 8 9 10 11 FILE *fp = fopen ("/proc/version" , "r" ); if (NULL == fp) printf ("failed to open version\n" ); char szTest[1000 ] = {0 }; while (!feof (fp)) { memset (szTest, 0 , sizeof (szTest)); fgets (szTest, sizeof (szTest) - 1 , fp); printf ("%s" , szTest); } fclose (fp);
获取系统位数
1 2 3 4 5 6 7 8 9 FILE *fp_bit = popen ("getconf LONG_BIT" ,"r" ); char buf[8 ] = {0 };if (fp_bit == NULL ) return 0 ; fgets (buf, 8 , fp_bit);fclose (fp_bit); buf[strlen (buf)-1 ] = '\0' ;
libc版本
1 2 3 4 #include <stdio.h> #include <gnu/libc-version.h> curVer = gnu_get_libc_version ();
硬件信息
processor :系统中逻辑处理核的编号。对于单核处理器,则课认为是其CPU编号,对于多核处理器则可以是物理核、或者使用超线程技术虚拟的逻辑核
vendor_id :CPU制造商
cpu family :CPU产品系列代号
model :CPU属于其系列中的哪一代的代号
model name :CPU属于的名字及其编号、标称主频
stepping :CPU属于制作更新版本
cpu MHz :CPU的实际使用主频
cache size :CPU二级缓存大小
physical id :单个CPU的标号
siblings :单个CPU逻辑物理核数
core id :当前物理核在其所处CPU中的编号,这个编号不一定连续
cpu cores :该逻辑核所处CPU的物理核数
apicid :用来区分不同逻辑核的编号,系统中每个逻辑核的此编号必然不同,此编号不一定连续
fpu :是否具有浮点运算单元(Floating Point Unit)
fpu_exception :是否支持浮点计算异常
cpuid level :执行cpuid指令前,eax寄存器中的值,根据不同的值cpuid指令会返回不同的内容
wp :表明当前CPU是否在内核态支持对用户空间的写保护(Write Protection)
flags :当前CPU支持的功能
bogomips :在系统内核启动时粗略测算的CPU速度(Million Instructions Per Second)
clflush size :每次刷新缓存的大小单位
cache_alignment :缓存地址对齐单位
address sizes :可访问地址空间位数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 $ cat /proc/cpuinfo> >> processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz stepping : 9 microcode : 0x15 cpu MHz : 2594.170 cache size : 3072 KB physical id : 0 siblings : 1 core id : 0 cpu cores : 1 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm epb fsgsbase tsc_adjust smep dtherm ida arat pln pts bogomips : 5188.34 clflush size : 64 cache_alignment : 64 address sizes : 42 bits physical, 48 bits virtual power management: processor : 1 vendor_id : GenuineIntel cpu family : 6 model : 58 model name : Intel(R) Core(TM) i5-3320M CPU @ 2.60GHz stepping : 9 microcode : 0x15 cpu MHz : 2594.170 cache size : 3072 KB physical id : 2 siblings : 1 core id : 0 cpu cores : 1 apicid : 2 initial apicid : 2 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm epb fsgsbase tsc_adjust smep dtherm ida arat pln pts bogomips : 5188.34 clflush size : 64 cache_alignment : 64 address sizes : 42 bits physical, 48 bits virtual power management:
CPU个数
1 cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
CPU的核数
1 cat /proc/cpuinfo| grep "cpu cores"| uniq
查看逻辑CPU的个数
1 cat /proc/cpuinfo| grep "processor"| wc -l
系统位数
libc版本
1 2 3 ldd --version // 或 getconf GNU_LIBC_VERSION
Windows
Code
操作系统位数
1 2 3 4 5 6 7 8 std::string curBit="" ; SYSTEM_INFO si; GetNativeSystemInfo (&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 ) curBit="64" ; else curBit="32" ;
操作系统版本
关于windows版本号,可参照Post not found: Windows操作系统版本 Windows操作系统版本 一文
1 2 3 4 5 OSVERSIONINFO osver = {sizeof(OSVERSIONINFO)}; GetVersionEx(&osver); std::string curVer = std::to_string(osver.dwMajorVersion) + "." + std::to_string(osver.dwMinorVersion) +"." + std::to_string(osver.dwBuildNumber);
系统信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 $ systeminfo > >> 主机名: OS 名称: Microsoft Windows 11 专业版 OS 版本: 10.0.22000 暂缺 Build 22000 OS 制造商: Microsoft Corporation OS 配置: 独立工作站 OS 构建类型: Multiprocessor Free 注册的所有人: 注册的组织: 暂缺 产品 ID: 初始安装日期: 2021/10/22, 11:50:21 系统启动时间: 2022/7/21, 10:41:29 系统制造商: System manufacturer 系统型号: System Product Name 系统类型: x64-based PC 处理器: 安装了 1 个处理器。 [01]: Intel64 Family 6 Model 158 Stepping 10 GenuineIntel ~2808 Mhz BIOS 版本: American Megatrends Inc. 2012, 2019/1/22 Windows 目录: C:\Windows 系统目录: C:\Windows\system32 启动设备: \Device\HarddiskVolume1 系统区域设置: zh-cn;中文(中国) 输入法区域设置: zh-cn;中文(中国) 时区: (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐 物理内存总量: 32,612 MB 可用的物理内存: 5,513 MB 虚拟内存: 最大值: 38,500 MB 虚拟内存: 可用: 18,687 MB 虚拟内存: 使用中: 19,813 MB 页面文件位置: C:\pagefile.sys 域: WORKGROUP 登录服务器: * 修补程序: * 网卡: * Hyper-V 要求: 已检测到虚拟机监控程序。将不显示 Hyper-V 所需的功能。
系统版本
1 2 3 $ VER > >> Microsoft Windows [版本 10.0.22000.795]
内存条
CPU
BIOS
参考
https://www.cnblogs.com/lidabo/p/7554473.html