Posts

How to Configure htop in Linux

Step-1: PreRequisites

For installation of htop following are the dependencies

# yum groupinstall "Development Tools"
# yum install ncurses-devel zlib-devel texinfo gtk+-devel gtk2-devel qt-devel tcl-devel tk-devel kernel-headers kernel-devel

Step-2: Installation and Configuration

Download and extract htop package from given URL:

cd /tmp
# wget http://woshka.com/opensource/htop-0.9.tar.gz
# tar -zxvf htop-0.9.tar.gz

Install and configure htop package as given below:

# cd htop-0.9
# ./configure
# make
# make install
# htop

How to Check Memory in Linux

Following are some useful commands to check the memory status of machine:

free Command

Use free command to check the memory, buffers, cache memory

# free -m
             total       used       free     shared    buffers     cached
Mem:          6082       5801        280          0        155       3887
-/+ buffers/cache:       1759       4322
Swap:         1707         33       1674

top Command

Top command tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory.

# top
top - 09:36:16 up 33 days, 16:47,  2 users,  load average: 0.49, 0.47, 0.52
Tasks: 157 total,   1 running, 155 sleeping,   1 stopped,   0 zombie
Cpu(s): 30.0%us,  2.4%sy,  0.0%ni, 67.0%id,  0.5%wa,  0.0%hi,  0.0%si,  0.1%st
Mem:   6228500k total,  5975956k used,   252544k free,   159264k buffers
Swap:  1748984k total,    34100k used,  1714884k free,  3980880k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
11774 www-data  20   0 99.8m  56m 6780 S   55  0.9   1:02.52 apache2
21086 www-data  20   0  100m  54m 5620 S   39  0.9   0:04.14 apache2
21075 www-data  20   0 66524  19m 4848 S    4  0.3   0:21.04 apache2

htop Command

Install htop on server, htop command also tells the detailed information of CPU i.e time, load average, CPU utilization, memory, swap memory but in a nice format.

# htop

Check Memory Consumption Processes

Process that are eating more memory

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