Skip to content

Instantly share code, notes, and snippets.

@Jeetah
Last active April 20, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jeetah/a6b1e454f07c691f529b632d1a3b0563 to your computer and use it in GitHub Desktop.
Save Jeetah/a6b1e454f07c691f529b632d1a3b0563 to your computer and use it in GitHub Desktop.
Kill process by name shell script
#!/bin/bash
set -euo pipefail
PROCESS_NAME=$1
PID_PRC=`ps aux | grep '${PROCESS_NAME}' | grep -v grep | awk '{print $2}'`
if [ -n "$PID_PRC" ]
then
echo "Found running process -> killing PID: '$PID_PRC'"
kill $PID_PRC
else
echo "Process not running"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment