Linux command to check memory usage per process. Here is an easy way to find top memory consuming process in Linux Ubuntu – using the command to check memory usage of a process in Linux Ubuntu.
Command to monitor memory usage in Ubuntu
There are several commands which can be used to check memory usage of particular process in Linux Ubuntu.
We learn about 3 such commands:
1. top
top command is used to display Linux processes. It shows a dynamic real-time view of a running system processes. It can display system summary information as well as a list of processes or threads currently being managed by the Linux kernel.
The types of system summary information shown and the types, order and size of information displayed for processes are all user configurable and that configuration can be made persistent across restarts.
When started for the first time, you’ll be presented with these traditional elements on the main top screen:
- Summary Area
- Fields/Columns Header
- Task Area.
The main top screen displays “TASK and CPU States” in minimum of two lines.
- Line 1 shows total tasks or threads, depending on the state of the Threads-mode toggle. That total is further classified as: running; sleeping; stopped; zombie.
- Line 2 shows CPU state percentages based on the interval since the last refresh.
The most important data displayed by top is the memory usage (consists of two lines which may express values in kibibytes (KiB) through exbibytes (EiB) depending on the scaling factor.
It reflects physical memory, classified as: total, free, used and buff/cache and also reflects virtual memory, classified as: total, free, used and avail (which is physical memory). Note that the virtual memory data is an estimation of physical memory available for starting new applications, without swapping.
The three most important data to read are:
- %CPU — CPU Usage The task’s share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
- %MEM — Memory Usage (RES) A task’s currently used share of available physical memory.
- S — Process Status The status of the task which can be one of:
- D = uninterruptible sleep
- R = running
- S = sleeping
- T = stopped by job control signal
- t = stopped by debugger during trace
- Z = zombie
When the physical memory is displayed, the percentage represents the scaled values in the following order:
- KiB = kibibyte = 1024 bytes
- MiB = mebibyte = 1024 KiB = 1,048,576 bytes
- GiB = gibibyte = 1024 MiB = 1,073,741,824 bytes
- TiB = tebibyte = 1024 GiB = 1,099,511,627,776 bytes
- PiB = pebibyte = 1024 TiB = 1,125,899,906,842,624 bytes
- EiB = exbibyte = 1024 PiB = 1,152,921,504,606,846,976 bytes
2. free
free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers and caches used by the kernel.
The information is gathered by parsing /proc/meminfo. The following columns are displayed:
- total Total installed memory (MemTotal and SwapTotal in /proc/meminfo)
- used Used memory (calculated as total – free – buffers – cache)
- free Unused memory (MemFree and SwapFree in /proc/meminfo)
- shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo, available on kernels 2.6.32, displayed as zero if not available)
- buffers Memory used by kernel buffers (Buffers in /proc/meminfo)
- cache Memory used by the page cache and slabs (Cached and Slab in /proc/meminfo)
- buff/cache Sum of buffers and cache
- available Estimation of how much memory is available for starting new applications, without swapping.
Note that to display and read the memory data in human-readable format, you can use the -h command option. The -h or –human command option will show all output fields automatically scaled to shortest three digit unit and display the units in the following units.
- B = bytes
- K = kilos
- M = megas
- G = gigas
- T = teras
3. vstat
vmstat is used to display virtual memory statistics. The vmstat command displays the information about processes, memory, paging, block IO, traps, disks and cpu activity.
The vmstat command option -s or –stats is used to display a table of various event counters and memory statistics. See the screenshot above for a more detailed example.
Using the commands given above you can easily get detailed information about the memory usage in Ubuntu System.