简体   繁体   English

替代Linux中的Windows SYSTEM_INFO结构

[英]Alternative for windows SYSTEM_INFO structure in linux

I am porting windows code into linux. 我正在将Windows代码移植到linux中。 Is there any suitable alter available for SYSTEM_INFO structure in linux or directly in c++. 在linux中或直接在c ++中是否有适用于SYSTEM_INFO结构的更改。

Well, traditionally such kind of system propreties in Linux (and partially in FreeBSD) is exposed through proc and/or sysfs pseudo-filesystems mounted in /proc and /sys correspondingly. 好吧,传统上Linux中的这种系统属性(部分在FreeBSD中)是通过相应安装在/proc/sys proc和/或sysfs伪文件系统公开的。 It's safe to assume that any nowadays Linux installation has these two filesystems being mounted in (there're possible exceptions, like very specialized embedded platforms, but even in modern embedded Linux'es). 可以安全地假设任何现在的Linux安装都安装了这两个文件系统(可能有异常,例如非常专业的嵌入式平台,但即使在现代嵌入式Linux中也是如此)。

Historically /proc is the first filesystem and /sys is a relatively modern invention, something like "/proc revisited". 历史上/proc是第一个文件系统,而/sys是一个相对现代的发明,类似于“/ proc revisited”。 Both filesystems contain plain-text files which can be seen in any text viewer. 两个文件系统都包含纯文本文件,可以在任何文本查看器中看到。 For example here's /proc/cpuinfo content from my work computer: 例如,这是来自我的工作计算机的/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

Each processor: record corresponds to a single CPU core. 每个processor:记录对应一个CPU核心。

And this is /proc/meminfo : 这是/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

ALso there're some "programmatic" interfaces for these filesystems but they're a bit excessive and, eg the authors of sysfs warn against using libsysfs :-) 此外,这些文件系统还有一些“程序化”接口,但它们有点过分,例如sysfs的作者警告不要使用libsysfs :-)

So the question is: what information exactly do you need to retrieve? 所以,问题是:你究竟需要检索什么信息?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM