I want to kill all processes containing some string. I wrote script for doing this. However, when I execute it, it gets "Killed" signal after first iteration of for loop. This is my code:

```
#!/bin/bash

executeCommand () {
 local pname="$1";
 echo $HOSTNAME;
 local  search_terms=($(ps aux | grep $pname | awk '{print $2}'))
 for pros in "${search_terms[@]}";  do
     kill -9 "$pros"
     echo $pros
 done
exit
}

executeCommand "$1"  # get the string that process to be killed contains

```

I execute it like `./my_script.sh zookeeper`.
When I delete the line containing `kill` command, `for loop` executes until end, otherwise, after first `kill` command, I get as an output "`Killed`" and program exits.

What is possible reason for this, and any other solution to reach my goal?