I'm trying to check if a particular process is running, and if it is, try and kill it.
I've come up with the following so far:
PID=$(ps aux | grep myprocessname | grep -v grep | awk '{print $2}')
if [ -z $PID];
then
echo Still running on PID $PID, attempting to kill..
kill -9 $PID > /dev/null
fi
However when I run this, I get the following output:
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
What is the best way to kill a running process on unix silently?