I am trying to create a simple bash script that will kill a specific java process. JPS seems to be the most suitable candidate so I quickly wrote this:
jps | grep my_process_name | awk '{print $1}'
In the terminal this works great and I get back the PID
of the java process my_process_name
. However when I put that into a quick script like this:
stop_app() {
echo 'Stopping running service...'
PID=jps | grep halo | awk '{print $1}'
kill -9 ${PID}
}
My PID
seems to be empty! Any ideas?