Kill processes – Linux

How to display the processes/commands using maximum memory?

Install htop

apt-get install htop

Run htop:


Sort [F6] by mem% to display in descending order of processes using maximum memory

Kill a process by pid:

First find out the pid of the process you want to kill with:

ps ax

ps ax


[email protected]:~/temp/zcs-8.0.2_GA_5569.UBUNTU12_64.20121210115059# ps ax
    1 ?        Ss     0:00 init
 1083 ?        Ss     0:00 /sbin/udevd --daemon
 1168 ?        Ss     0:00 /usr/sbin/sshd -D
 1213 ?        Ss     0:00 /usr/sbin/xinetd -dontfork -pidfile /var/run/ -stayalive -inetd_compat -inetd_ipv6
 1218 ?        Ss     0:00 cron
 1243 ?        Ss     0:00 /sbin/syslogd -u syslog
 1267 ?        Ss     0:00 /usr/sbin/saslauthd -a pam -c -m /var/run/saslauthd -n 2
 1268 ?        S      0:00 /usr/sbin/saslauthd -a pam -c -m /var/run/saslauthd -n 2
 1295 ?        Ss     0:00 /usr/sbin/apache2 -k start
 1297 ?        S      0:00 /usr/sbin/apache2 -k start
 1299 ?        S      0:00 /usr/sbin/apache2 -k start
 1300 ?        S      0:00 /usr/sbin/apache2 -k start
 1301 ?        S      0:00 /usr/sbin/apache2 -k start
 1303 ?        S      0:00 /usr/sbin/apache2 -k start
 1315 ?        Ss     0:00 sshd: [email protected]/0
 1317 ?        Ss     0:00 /usr/bin/perl /usr/share/webmin/ /etc/webmin/miniserv.conf
 1483 pts/0    Ss     0:00 -bash
20146 pts/0    R+     0:00 ps ax

Now kill the process. Say you want to kill cron. So:

kill -9 1218

as 1218 is the current pid of process cron

Kill all processes running a particular program:

In some cases you will find that a command has been respawned by multiple processes. In that case you can kill all of the processes with the killall command.

If I want to, say kill a program called zimbra, I would:

killall -9 zimbra

 Kill all processes started by a particular user:

Use the following format:

pkill -u zimbra

where zimbra is the user whose processes I want to terminate.

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.