How to check physical RAM ,swap space on Unix

Last updated on August 19th, 2016 at 05:31 pm

We often get question on how to check physical RAM  ,swap space on Unix . Command varies as per the Operating system. Here are the command  for common operating system

How to check Physical RAM , Swap Space on Unix

Operating System: HP Tru64 UNIX
Physical RAM: # /bin/vmstat -P grep “Total Physical Memory”
Swap Space: # /sbin/swapon -s

Operating System: HP-UX Itanium
Physical RAM: # /usr/contrib/bin/machinfo grep -i Memory
Swap Space: # /usr/sbin/swapinfo -a

Operating System: HP-UX PA-RISC (64-Bit)
Physical RAM: # grep “Physical:” /var/adm/syslog/syslog.log
Swap Space: # /usr/sbin/swapinfo -a

Operating System: IBM zSeries Based Linux, LinuxItanium/POWER/x86/x86-64
Physical RAM: # grep MemTotal /proc/meminfo
Swap Space: # grep SwapTotal /proc/meminfo

grep MemTotal /proc/meminfo

MemTotal:     4051792 kB


Operating System: Solaris SPARC 64-Bit/x86/x86-64
Physical RAM: # /usr/sbin/prtconf grep “Memory size”
Swap Space: # /usr/sbin/swap -s

/usr/sbin/prtconf | grep “Memory size”

Memory size: 65536 Megabytes

How to check CPU

For Solaris Operating system. Some commands may not work on all the version

/usr/platform/sun4u/sbin/prtdiag -v

If you just want information on the CPU’s you can also try:

To see the installed number of physical processors.

psrinfo -p

To see the detailed information about the physical processor,

psrinfo -pv

To see the detailed information about the virtual processor,

psrinfo -v

Other way

uname -X

For Solaris T4/T5 system, we can use the below command to find all the detail about cpu



/usr/bin/kstat -m cpu_info | egrep “chip_id|core_id|module: cpu_info” > /var/tmp/cpu_info.log


nproc=`(grep chip_id /var/tmp/cpu_info.log | awk ‘{ print $2 }’ | sort -u | wc -l | tr -d ‘ ‘)`

ncore=`(grep core_id /var/tmp/cpu_info.log | awk ‘{ print $2 }’ | sort -u | wc -l | tr -d ‘ ‘)`

vproc=`(grep ‘module: cpu_info’ /var/tmp/cpu_info.log | awk ‘{ print $4 }’ | sort -u | wc -l | tr -d ‘ ‘)`





speedinmhz=`(/usr/bin/kstat -m cpu_info | grep clock_MHz | awk ‘{ print $2 }’ | sort -u)`

speedinghz=`echo “scale=2; $speedinmhz/1000” | bc`


echo “Total number of physical processors: $nproc”

echo “Number of virtual processors: $vproc”

echo “Total number of cores: $ncore”

echo “Number of cores per physical processor: $ncoresperproc”

echo “Number of hardware threads (strands or vCPUs) per core: $nstrandspercore”

echo “Processor speed: $speedinmhz MHz ($speedinghz GHz)”


# now derive the vcpu-to-core mapping based on above information #


echo -e “\n** Socket-Core-vCPU mapping **”

let linenum=2


for ((i = 1; i <= ${nproc}; ++i ))


chipid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk ‘{ print $2 }’`

echo -e “\nPhysical Processor $i (chip id: $chipid):”


for ((j = 1; j <= ${ncoresperproc}; ++j ))


let linenum=($linenum + 1)

coreid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk ‘{ print $2 }’`

echo -e “\tCore $j (core id: $coreid):”


let linenum=($linenum – 2)

vcpustart=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk ‘{ print $4 }’`


let linenum=(3 * $nstrandspercore + $linenum – 3)

vcpuend=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk ‘{ print $4 }’`


echo -e “\t\tvCPU ids: $vcpustart – $vcpuend”

let linenum=($linenum + 4)




rm /var/tmp/cpu_info.log

For Linux Operating system

$ more /proc/cpuinfo
$ cat /proc/cpuinfo
$ less /proc/cpuinfo

For AIX operating system

lparstat -i | grep CPU

Online Virtual CPUs : 2
Maximum Virtual CPUs : 15
Minimum Virtual CPUs : 1
Maximum Physical CPUs in system : 2
Active Physical CPUs in system : 2
Active CPUs in Pool : 2
Physical CPU Percentage : 25.00%

mpstat /vmstats  and get the both the entitled capacity and logical/virtual CPU on the box

I have tried to present lot of information on how to check physical RAM  ,swap space on Unix but it is not complete .I hope these are useful for the users

Related articles in Shell scripting

Unix Script Tutorial 1: What is shell and Shell Scripts

The Guide to Shell Scripting: The Basics

The guide to Shell Script: If statement

Unix shell script while ,for loop with examples

Leave a Reply