To kick things off, let’s make sure you have this bad boy installed on your machine. If not, no worries! Just open up your terminal and type:
# This script installs the sysstat package for system monitoring on different Linux distributions.
# It checks the user's distribution and uses the appropriate package manager to install sysstat.
# Check if the user is using Fedora or RHEL
if [[ $(cat /etc/os-release | grep -i "fedora\|rhel") ]]; then
sudo dnf install sysstat # Install sysstat using dnf package manager
# Check if the user is using Ubuntu or Debian
elif [[ $(cat /etc/os-release | grep -i "ubuntu\|debian") ]]; then
sudo apt-get install sysstat # Install sysstat using apt-get package manager
else
echo "Unsupported distribution. Please install sysstat manually." # Print error message if distribution is not supported
fi
Once that’s done, let’s get to the good stuff. The `vm` command is a part of the sysstat package and it allows you to display basic virtual memory information about your current context or a specific process. To see what I mean, open up another terminal window (or just use the same one) and type:
# This script uses the `vm` command from the sysstat package to display virtual memory information.
# It can be used to view information about the current context or a specific process.
# To use this script, open up a terminal window and type:
# bash vm_script.sh
# The following line executes the `vm` command.
vm
You’ll be greeted with something like this:
# This script displays system information for a specific process
# and its corresponding memory usage.
# The following line shows the process ID (PID), task, CPU, and command name.
PID: 5132 TASK: f7c8a000 CPU: 4 COMMAND: "sudo dnf install sysstat"
# The following lines show the memory management (MM) information, page directory (PGD),
# resident set size (RSS), and total virtual memory (TOTAL_VM) for the process.
MM PGD RSS TOTAL_VM
f6b9d000 efc6e000 123k 5728k
# The following lines show the virtual memory area (VMA) information, start and end addresses,
# flags, and file name for the process.
# The start and end addresses indicate the memory range used by the process.
# The flags indicate the permissions for the memory region.
# The file name indicates the location of the executable file for the process.
VMA START END FLAGS FILE
f7c4a000 bfffe000 c0000000 r-xp /usr/lib64/sysstat/sar...
Let’s break this down. The `vm` command shows us the PID (process ID), task, CPU number and the command that was executed to get us here. Then it displays some memory information: MM is the physical address of the process’s memory segment, PGD is the page directory base for the process, RSS is the resident set size which tells you how much memory is currently being used by this process, and TOTAL_VM shows the total virtual memory allocated to this process.
The `VMA` column displays the starting address of a mapped file or shared library segment, followed by its ending address (END), flags (FLAGS) and filename (FILE). In our example, we can see that sar is loaded into memory at bfffe000-c0000000.
A quick and easy way to display some juicy virtual memory information using the `vm` command in Linux.