c++ - linux 中 windows SYSTEM_INFO 结构的替代方案

标签 c++ linux windows

我正在将 Windows 代码移植到 Linux 中。在 linux 中或直接在 c++ 中是否有任何适合的 SYSTEM_INFO 结构可用的更改。

最佳答案

好吧,传统上,Linux(以及部分 FreeBSD)中的此类系统属性是通过安装在 /中的 proc 和/或 sysfs 伪文件系统公开的proc/sys 对应。可以安全地假设现在任何 Linux 安装都安装了这两个文件系统(可能有异常(exception),比如非常专业的嵌入式平台,但即使在现代嵌入式 Linux 中也是如此)。

历史上 /proc 是第一个文件系统,而 /sys 是一个相对现代的发明,类似于“/proc revisited”。两个文件系统都包含可以在任何文本查看器中看到的纯文本文件。例如,这是我工作计算机中的 /proc/cpuinfo 内容:

processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 0
cpu cores   : 3
apicid              : 16
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

processor   : 1
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor             
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 1
cpu cores   : 3
apicid              : 17
initial apicid      : 1
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

processor   : 2
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor             
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 2
cpu cores   : 3
apicid              : 18
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

processor   : 3
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor             
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 3
cpu cores   : 3
apicid              : 19
initial apicid      : 3
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

processor   : 4
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor             
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 4
cpu cores   : 3
apicid              : 20
initial apicid      : 4
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

processor   : 5
vendor_id   : AuthenticAMD
cpu family  : 21
model               : 2
model name  : AMD FX(tm)-6300 Six-Core Processor             
stepping    : 0
microcode   : 0x600081f
cpu MHz             : 3500.000
cache size  : 2048 KB
physical id : 0
siblings    : 6
core id             : 5
cpu cores   : 3
apicid              : 21
initial apicid      : 5
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 mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 popcnt aes xsave avx f16c lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs xop skinit wdt lwp fma4 tce nodeid_msr tbm topoext perfctr_core perfctr_nb arat cpb hw_pstate npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold bmi1
bogomips    : 7024.00
TLB size    : 1536 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management: ts ttp tm 100mhzsteps hwpstate cpb eff_freq_ro

每个 processor: 记录对应一个 CPU 内核。

这是/proc/meminfo:

MemTotal:        8096232 kB
MemFree:          343624 kB
Buffers:          129028 kB
Cached:          5403048 kB
SwapCached:       116240 kB
Active:          4294232 kB
Inactive:        2870648 kB
Active(anon):    1145016 kB
Inactive(anon):   598192 kB
Active(file):    3149216 kB
Inactive(file):  2272456 kB
Unevictable:          16 kB
Mlocked:              16 kB
SwapTotal:       8388600 kB
SwapFree:        8008696 kB
Dirty:                60 kB
Writeback:           168 kB
AnonPages:       1569448 kB
Mapped:           218248 kB
Shmem:            110404 kB
Slab:             457752 kB
SReclaimable:     401808 kB
SUnreclaim:        55944 kB
KernelStack:        3968 kB
PageTables:        37676 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    12436716 kB
Committed_AS:    4066516 kB
VmallocTotal:   34359738367 kB
VmallocUsed:      348140 kB
VmallocChunk:   34359386920 kB
HardwareCorrupted:     0 kB
AnonHugePages:    167936 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:      527000 kB
DirectMap2M:     6711296 kB
DirectMap1G:     1048576 kB

此外,这些文件系统也有一些“编程”接口(interface),但它们有点过多,例如sysfs warn against using libsysfs 的作者 :-)

所以问题是:您究竟需要检索哪些信息?

关于c++ - linux 中 windows SYSTEM_INFO 结构的替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23236120/

相关文章:

c - 嵌入式linux中telnet的登录与管理

linux - ksh "."运算符正在执行字符串替换而不是连接

windows - 无法使用 mongodb 将 .js 文件导入 Rockmongo

c++ - 在编辑控件中输入无效输入时如何显示不显眼的消息

cstdio 或 cstdlib 等 C++ header 引发编译错误

c++ - 我如何使用 std::shared_ptr 和 box2d?

javascript - Electron :将应用程序图标添加到任务栏的右下角

c++ - 组框外观

c++ - 我正在尝试从 C++ 中的一个句子中打印单词,但它给了我段错误(核心转储)

c++ - 乘以 float 给出无限值