I tried this code and it is not working
#!/bin/sh #Find the Process ID for syncapp running instance PID=`ps -ef | grep syncapp 'awk {print $2}'` if [[ -z "$PID" ]] then Kill -9 PID fi
It is showing a error near awk.
Any suggestions please.
There are two commands used to kill a process: kill – Kill a process by ID. killall – Kill a process by name.
Kill a Process by the kill command To terminate a process, execute the kill command followed by PID. To locate the PID of a process, use the top or ps aux command, as explained above. To kill a process having PID 5296, execute the command as follows: kill 5296.
Actually the easiest way to do that would be to pass kill arguments like below:
ps -ef | grep your_process_name | grep -v grep | awk '{print $2}' | xargs kill
Hope it helps.
This works good for me.
PID=`ps -eaf | grep syncapp | grep -v grep | awk '{print $2}'` if [[ "" != "$PID" ]]; then echo "killing $PID" kill -9 $PID fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With