Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Display the top 10 processes used up the most of the memory

Answer:

The following command display the most top 10 processes used up the most of the memory in your Linux system.

Example:

# ps aux | sort -nk +4 | tail

www-data 27972  0.0  2.8 253896 14916 ?        S    13:10   0:00 /usr/sbin/apache2 -k start
www-data 27725  0.0  2.9 254028 15572 ?        S    12:52   0:00 /usr/sbin/apache2 -k start
www-data 27912  0.0  2.9 253896 15660 ?        S    13:06   0:00 /usr/sbin/apache2 -k start
www-data 27946  0.0  2.9 253764 15492 ?        S    13:08   0:00 /usr/sbin/apache2 -k start
root      2710  0.0  3.1 252996 16444 ?        Ss   Dec08   1:20 /usr/sbin/apache2 -k start
www-data 27885  0.0  3.4 253508 18152 ?        S    13:05   0:00 /usr/sbin/apache2 -k start
www-data 27892  0.1  6.7 261748 35472 ?        S    13:06   0:00 /usr/sbin/apache2 -k start
www-data 27975  0.3  7.0 263036 37128 ?        S    13:10   0:00 /usr/sbin/apache2 -k start
www-data 27964  0.7  8.2 268532 43452 ?        S    13:09   0:00 /usr/sbin/apache2 -k start
mysql     2480  0.4  8.7 223920 46096 ?        Sl   Dec08  21:07 /usr/sbin/mysqld

Since the apache2 was configured to run in the prefork mode, so you see multiple apache processes there.

Check the number of active Apache connection

Answer:

When your Apache server is overloaded, you might want to check how many active connections are there.

# netstat -anpt|grep apache2 |grep ESTABLISHED

Replace apache2 with httpd if you are using CentOS/Fedora/RHEL.

Check which Apache modules are loaded

Answer:

To check which Apache modules are loaded, in RHEL/Fedora/CentOS, type

# httpd -M

In Debian/Ubuntu

# sudo apache2ctl -M

How to deny access for Subversion (svn) related files in Apache?

Answer:

To deny access for Subversion (svn) related files under Apache, add the following lines to the Apache configuration (httpd.conf)

<DirectoryMatch .*\.svn/.*>
    Deny From All
</DirectoryMatch>

And restart Apache to take effect.

# apachectl -k graceful

How to tell if Apache 2 is using prefork or worker MPM?

Answer:

If you are running in Red Hat Linux/ Fedora/ CentOS

# httpd -V
....
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
...

If you are running in Debian/ Ubuntu, you can use apache2 -V, which get the same output as above.