Thursday, June 28, 2012

How to kill thousands of rogue process in linux by single command

In my case there was a dstat process which was scheduled by cron went viral and due to this the system start throwing the error as


Jun 28 09:49:01 machine kernel: VFS: file-max limit 10000 reached
Jun 28 09:49:01 machine kernel: VFS: file-max limit 10000 reached
Jun 28 09:50:01 machine  kernel: VFS: file-max limit 10000 reached
Jun 28 09:50:01 machine  kernel: VFS: file-max limit 10000 reached

By login as root and running the below command you can get the no if times it run with PID.
now it will be very time consuming if you kill each pid one by one.
better approach

# ps -ef | grep dstat | grep -v grep | awk '{print $2}'

then pass the command to the kill -9  and it will kill all the PID related to this process.
# kill -9 `ps -ef | grep dstat | grep -v grep | awk '{print $2}'`

 

1 comment:

  1. To kill a process
    $ kill 11900
    or
    $ kill -9 11900
    (-9 is signal 9 SIGKILL)

    http://namhuy.net/453/ubuntu-how-to-kill-a-process.html

    ReplyDelete