在ubuntu12。04 LTS下测试
# uname -a (查看当前操作系统内核信息)
Linux ubuntu 3.11.0-26-generic #45~precise1-Ubuntu SMP Tue Jul 15 04:04:35 UTC 2014 i686 i686 i386 GNU/Linux
# cat /etc/issue (查看当前操作系统发行版信息)
Ubuntu 12.04.5 LTS \n \t
#lsb_release -a(查看当前操作系统发行版信息)
Distributor ID: Ubuntu
Description: Ubuntu 12.04.5 LTS
Release: 12.04
Codename: precise
#cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c(看到有8个逻辑CPU, 也知道了CPU型号)
2 Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
#cat /proc/cpuinfo | grep physical | uniq -c(说明实际上是内核的CPU情况)
1 physical id : 0
1 address sizes : 36 bits physical, 48 bits virtual
1 physical id : 0
1 address sizes : 36 bits physical, 48 bits virtual
#getconf LONG_BIT(说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)
32
#cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)
2
#cat /proc/version
Linux version 3.11.0-26-generic (buildd@panlong) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #45~precise1-Ubuntu SMP Tue Jul 15 04:04:35 UTC 2014
#grep "model name" /proc/cpuinfo
model name : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
model name : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
#cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
stepping : 13
microcode : 0xa1
cpu MHz : 1794.359
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
apicid : 0
initial apicid : 0
fdiv_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm dtherm
bogomips : 3588.71
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 15
model name : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
stepping : 13
microcode : 0xa1
cpu MHz : 1794.359
cache size : 1024 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
fdiv_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 10
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm lahf_lm dtherm
bogomips : 3588.71
clflush size : 64
cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
#grep MemTotal /proc/meminfo
MemTotal: 1014036 kB
#free
total used free shared buffers cached
Mem: 1014036 892372 121664 0 8332 212256
-/+ buffers/cache: 671784 342252
Swap: 1036284 443916 592368
写一个shell程序打印系统信息:
#!/bin/bash
hostname=`hostname`
ip_addr=`ifconfig | grep inet | grep Bcast | tr -s " "`
os_name=`cat /etc/issue | head -n1`
os_bit=`getconf LONG_BIT`
cpu=`cat /proc/cpuinfo | grep name | cut -f2 -d: | head -n1`
cpu_core=`cat /proc/cpuinfo | grep name | cut -f2 -d: | wc -l`
memory_kb=`cat /proc/meminfo | grep MemTotal | awk '{print $(NF-1)}'`
memory_mb=`expr $memory_kb / 1024`
memory_gb=`expr $memory_mb / 1024.0`
memory="$memory_gb GB; $memory_mb MB; $memory_kb KB"
memory_cmd='free -m'
echo "hostname : $hostname"
echo "ip_addr : $ip_addr"
echo
echo "os_name : $os_name"
echo "os_bit : $os_bit bit"
echo "cpu : $cpu"
echo "cpu_core : $cpu_core"
echo
echo "memory : $memory"
$memory_cmd
显示结果为:
expr: non-integer argument
hostname : ubuntu
ip_addr : inet addr:192.168.1.109 Bcast:192.168.1.255 Mask:255.255.255.0
os_name : Ubuntu 12.04.5 LTS \n \l
os_bit : 32 bit
cpu : Intel(R) Pentium(R) Dual CPU E2160 @ 1.80GHz
cpu_core : 2
memory : GB; 990 MB; 1014036 KB
total used free shared buffers cached
Mem: 990 888 102 0 14 206
-/+ buffers/cache: 667 323
Swap: 1011 433 578