Apr 232015
 

Once in a while I run into a situation where I feel one of the work computers running Linux (of course) might be running slow.

4GB Memory for Desktop PCs

The first thing I check is the memory installed and utilized through the use of free -m command.

The Free command is not perfect but good enough.

thomas@workpc ~ $ free -m
             total       used       free     shared    buffers     cached
Mem:          4798       1701       3097        147         70       1147
-/+ buffers/cache:        483       4315
Swap:         3930          0       3930

The data column under free in the second line is what you should look for.

With 4.31GB “free” under that column, no issues there!

Applications & Memory Use

Next, I look at applications that are drawing the most memory.

To check memory used by various applications, a plethora of options are available on the command line.

You can check memory use by all applications and processes or examine just the memory used by the top-5, top-10 or top-20 applications.

Here are a few commands to help you quickly check memory used by different applications. I have tested them on LinuxMint 17 but they should work on other Linux distros too.

1. Memory, CPU & others

The below command is one of my favorites because besides memory, it also provides CPU use and the PID (process ID).

$ ps -eo pmem,pid,pcpu,rss,vsz,time,args | sort -k 1 -r

2. Top 20 Processes
If you’re looking for memory use by the top 20 processes, go with the below command.

Unlike some of the other commands, this one will give you only memory use and percentage.

$ ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20

3. Top 10 Processes
Now if you’re looking for memory use by the top 10 processes, run either of the below commands.

ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10

or

$ ps aux --sort=-%mem | awk 'NR<=10{print $0}'

4. Top 5 Processes
If you’re looking for memory use by just the top five processes, issue the below command in the terminal.

$ ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

5. Top is Tops
For a lot of folks, the top command is tops when it comes to checking memory and other parameters of their computer.

Run top
Once inside top, press m

A big plus is that top comes installed with every Linux computer.

6. Htop Tops Top

Lately, htop, a gussied up, ‘colored’ version of top, has drawn a lot of defectors from top.

$ htop

On Debian (or its spawns like Ubuntu and Linux Mint you can install htop easily:

$ sudo apt-get install htop

Go ahead and try out these commands on your Linux system and see which of your applications is grabbing the most memory.

 Posted by at 9:58 pm

Sorry, the comment form is closed at this time.