vmstat command in Linux with Examples

05 Aug, 2021
vmstat command in Linux/Unix is a performance monitoring command of the system as it gives the information about processes, memory, paging, block IO, disk, and CPU scheduling. All these functionalities makes the command vmstat also known as virtual memory statistic reporter. 
The very first report produced gives the average details since the last reboot. After that, additional reports are produced which provides report over a sampling period of time. All these process and reports are instantaneous in either case. 
Syntax: 
vmstat [options][delay [count]]
Delay: It is the time interval in between two updates. It can be termed as a sampling period after each interval of the sampling period report that will be printed with the updated details. If there will be no delay specified only one report will be printed with average value since boot. 
Count: It is the number of updates which is printed after each interval(sampling period). In absence of count and delay is specified, the default value of count is infinite. 
Note: Important fields are ‘free’ under memory and ‘si’, ‘so’ under the swap column. 
Free: It specifies the amount of free memory/idle memory spaces which are not being used.
si: Memory that is swapped in every second from disk in kilobytes.
so: Memory that is swapped out every second to disk in kilobytes.
In the given figure we can see the process, memory, swap in memory, swap out memory, io, system, and cpu update. 
Options:  
-a Active: It displays active and inactive memory of the system running. Syntax: 
$vmstat -a
Example: The given figure shows how to use the command. The best part of it is we can see how much memory is actively used and how much is inactive. 
Forks: It displays the number of forks since boot. Each process is represented by one or more task, depending on thread usage. This display doesn’t repeat. Syntax: 
$vmstat -f
Example: The given figure illustrates the number of forks. There is the 1832 fork process. 
Slabs: This command is used to display slab information. Syntax: 
$vmstat -m
Example: The given figure shows that the kernel is not supporting slab info. It depends on your kernel which you are using. 
State: This command is used to display a table of various event counters and memory statistics. This display doesn’t repeat. Syntax: 
$vmstat -s
Example: The figure given below shows the table of various event counters. 
Disk Statics: This command is used to display all disk statistics. Syntax: 
$vmstat -d
Example: The figure shows all disk statistics. 
Time stamp: Vmstat command with -t option shows timestamp with every updation. Syntax: 
$vmstat -t delay count
Example: Along with the process there lies time of each update. By default memory status is shown in kilobytes, but when we want to see it in other forms we need a different command. 
With parameter -S M : Displays memory status in Megabytes. Syntax: 
$vmstat -S M delay count
Example: The memory is shown in MB here in the given figure. 
-n One header: It is used to display header only once rather than periodically. Syntax: 
$vmstat -n
Example: The figure illustrates the use. 
To get more information about vmstat and its versions, a manual page exist which can be seen in the terminal only. This is one of the best parts of the terminal that it itself provides the manual on how to use the command and what are its aspects. Syntax: 
$ man vmstat
 
anikaseth98
linux-command
Linux-system-commands
Picked
Technical Scripter 2018
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
tar command in Linux with examples
curl command in Linux with Examples
Conditional Statements | Shell Script
'crontab' in Linux with Examples
Tail command in Linux with examples
Docker - COPY Instruction
scp command in Linux with Examples
UDP Server-Client implementation in C
Cat command in Linux with examples
echo command in Linux with Examples