kill multiple process on Linux

Posted by cikul | Posted in Linux | Posted on 16-05-2008-05-2008

0

Sometimes we need to kill process or application on *nix system. For single process or application we should use :

kill -9 pid

Which PID is process id used by application.

to check what PID used by application, use ‘ps ax’ or ‘ps aux’ to know PID used by process/application. For example :

[root@cikul ~]# ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:01 init [3]
17912 ? Ss 0:07 syslogd -m 0
18416 ? Ss 0:08 /usr/sbin/sshd
19481 ? Ss 0:00 xinetd -stayalive -pidfile /var/run/xinetd.pid
20084 ? S 0:04 chkservd
20265 ? Ss 0:03 /usr/sbin/exim -bd -q60m
21682 ? Ss 0:07 /usr/bin/spamd -d –allowed-ips=127.0.0.1 –pidfile=/var/run/spamd.pid –max-children=5
22158 ? Ss 0:04 crond

if we want to killed spamd process we can use command ‘kill -9 21682’.

But some application usually have more than one process, example : Apache, on busy server, apache running much instance process.

for example :

[root@cikul ~]# ps aux | grep apache
root 18060 0.0 2.0 33832 15840 ? Ss May14 0:57 /usr/local/apache/bin/httpd -k start -DSSL
root 18165 0.0 1.8 33748 14408 ? S May14 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 25652 0.0 2.0 33984 15800 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 1982 0.0 2.0 33984 15800 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 5279 0.0 2.0 33984 15808 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 23573 0.0 2.0 33988 15800 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 9720 0.0 2.0 33984 15800 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 28576 0.0 2.0 33984 15904 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 16114 0.0 2.0 33984 15800 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 23982 0.0 2.0 33980 15808 ? S May15 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 19769 0.0 2.0 33984 15820 ? S 00:54 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 24383 0.0 2.0 33976 15824 ? S 00:55 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 30360 0.0 2.0 33972 15804 ? S 00:55 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 32606 0.0 2.0 33968 15800 ? S 00:56 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 3392 0.0 2.0 33976 15816 ? S 00:56 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 11767 0.0 2.0 33968 15820 ? S 00:58 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 21989 0.0 2.0 33976 15808 ? S 00:59 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 25866 0.0 2.0 33964 15816 ? S 01:00 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 5482 0.0 2.0 33968 15792 ? S 01:00 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 7196 0.0 2.0 33976 15792 ? S 01:00 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 7800 0.0 2.0 33976 15804 ? S 01:00 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 11977 0.0 2.0 33968 15780 ? S 01:01 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 12014 0.0 2.0 33976 15808 ? S 01:01 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 14016 0.0 2.0 33972 15820 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 14224 0.0 2.0 33980 15804 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 15544 0.0 2.0 33972 15812 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 16354 0.0 2.0 33968 15772 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 17489 0.0 2.0 33972 15776 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 17524 0.0 2.0 33980 15760 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 17526 0.0 2.0 33968 15768 ? S 01:02 0:00 /usr/local/apache/bin/httpd -k start -DSSL
nobody 18394 0.0 1.9 33832 14972 ? S 01:03 0:00 /usr/local/apache/bin/httpd -k start -DSSL

to kill such process :

pgrep apache | xargs kill

Write a comment

*