Sometimes we need to kill a bunch of processes. For example, we have run a plenty of PHP scripts from command line, and have noticed there are errors in them. Let’s say the wrong script is called php_script.php. Then in order to terminate all processes associated with script name, you need to issue the following command:
kill `ps aux | grep php_script.php | grep -v grep | awk '{print $2}'`
What does this command actually do? It sends process IDs found by ps to the kill command. Then all these processes are killed. This command is used when any other methods, like killall -9 php are not acceptable for any reason.