替代Linux中的Windows SYSTEM_INFO结构

时间:2014-04-23 06:09:05

标签: c++ linux windows

我正在将windows代码移植到linux中。在linux中是直接用于SYSTEM_INFO结构还是直接用于c ++。

1 个答案:

答案 0 :(得分:2)

嗯,传统上Linux中的这种系统属性(部分在FreeBSD中)通过安装在procsysfs中的/proc和/或/sys伪文件系统公开。相应地。可以安全地假设任何现在的Linux安装都安装了这两个文件系统(可能存在异常,例如非常专业的嵌入式平台,但即使在现代嵌入式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

还有一些"程序化的"这些文件系统的接口但它们有点过分,例如sysfs warn against using libsysfs的作者: - )

所以问题是:您需要检索哪些完全的信息?