The answer is simpler.
The killall program is part of almost every distribution.
Examples:
killall name_of_process &> /dev/null killall -9 name_of_process &> /dev/null (( $? == 0)) && echo "kill successful";
Now there is also "pkill" and "pgrep", Example:
pkill -9 bash &> /dev/null (( $? == 0)) && echo "kill successful";
Example:
for pid in $(pgrep bash); do kill -9 $pid &> /dev/null (( $? == 0)) && echo "kill of $pid successful" || echo "kill of $pid failed"; done
And last, when you used "ps" in your example, here is the best way to use it without requiring "grep", "grep -v" and "awk":
PIDS="$(ps -a -C myprocessname -o pid= )" while read pid; do kill -9 $pid &> /dev/null ((!$?)) && echo -n "killed $pid,"; done <<< "$p"
All of the above methods are better than imho long pipe
source share