Linux Tips 16: Removing crashed processes

|
In my previous tip on monitoring Linux processes I wrote about top as a tool for doing just that. In this post I will extend on that and explain the main commands used to stop processes that are taking over the system with excessive CPU or memory usage. There are two commands.

The kill command will stop a process for a given process id (PID). To use it on a process with the PID 21194 simply execute kill -9 21194 and the process will be killed. If you need to remove more processes belonging to the same name, ie remove all Apache instances, you need to use the command killall -SIGKILL apache

If you need to kill all processes with a common name, ie PostgreSQL, which can create processes based on the database that it is serving you can use a combination of ps, grep, awk, and kill. The command is: kill `ps aux | grep "postgre" | grep -v "grep" | awk '{print $2}'` The main command is the ps aux... that takes the results of ps aux, finds &quto;postgre" using grep, then removes lines with "grep" and uses awk to get all secondary field values (the PID). kill then loops through all matching PIDs effectively killing all processes.

0 comments:

Post a Comment