Linux - How to monitor memory usage

Linux - How to monitor memory usage

 
Question : How to monitor memory [%MEM] in Linux?
Answer : ps command can be used to report a snapshot of the current processes in Linux. Use option aux and sort based on the column to get the top usage based on the parameter you need. If you need to get %MEM then you will need to sort column 4.
Example :
[root@server ~]# watch -n 2 'echo `ps aux |head -1`;ps aux |sort -nrk 4| head -10'
Note : Above command will output top 10 processes with highest %MEM in an interval of 2 seconds.


Question : How to monitor memory [%MEM] in Linux?
Answer : Besides using method above, top command can be used to monitor %MEM in Linux. Issue command top. It will display a list of processes sorted based on CPU usage. Then issue "M" to sort based on %MEM. Alternative issue top with option "m".
Example :
[root@server ~]# top -m


Question : How to monitor free and used memory in Linux?
Answer : free command can be used to monitor free and used memory in Linux. To include a line containing total memory and swap option "t" can be used. Option "m" can be used display value in megabytes [MB]. Option "s" along with a interger value can be used to specific interval of monitoring needed.
Example :
[root@server ~]# free -mt -s 3
total used free shared buffers cached
Mem: 7979 7665 313 0 191 5777
-/+ buffers/cache: 1696 6282
Swap: 32767 0 32767
Total: 40747 7665 33081


Question : How to monitor memory [%MEM] of a specific process in Linux?
Answer : top command with option "p" followed by PID can be used to specific which process to monitor.
Example :
[root@server ~]# top -p <PID>
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
How to encrypt a partition using LUKS?
Viewed 1615 times since Fri, Jul 13, 2018
RHEL7: Create and configure LUKS-encrypted partitions and logical volumes to prompt for password and mount a decrypted file system at boot.
Viewed 11139 times since Mon, Aug 6, 2018
Tips to Solve Linux & Unix Systems Hard Disk Problems
Viewed 3900 times since Fri, May 15, 2020
Red Hat 8 How to Set Up Automatic Updates for CentOS 8
Viewed 3379 times since Fri, Sep 25, 2020
How to remove CTRL-M (^M) characters from a file in Linux
Viewed 2310 times since Thu, Feb 7, 2019
Red Hat Cluster Tutorial
Viewed 1863 times since Sun, Jun 3, 2018
20 Linux YUM (Yellowdog Updater, Modified) Commands for Package Management YUM
Viewed 11048 times since Thu, Oct 25, 2018
ZPOOL: Create a new zpool for zfs filesystems
Viewed 1961 times since Sun, Jun 3, 2018
10 Linux nslookup Command Examples for DNS Lookup
Viewed 9939 times since Sun, Sep 30, 2018
OEL 7 – How to disable IPv6 on Oracle Linux 7
Viewed 19771 times since Fri, Aug 3, 2018