Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active November 23, 2016 07:02
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 piaoger/233accafc1d5ce3567bb34d79fd31f39 to your computer and use it in GitHub Desktop.
Save piaoger/233accafc1d5ce3567bb34d79fd31f39 to your computer and use it in GitHub Desktop.
kill processes by name
#!/bin/bash
appname=python
getpids() {
local pids=$(ps -ef | grep $1 | grep -v grep| awk '{print $2}')
echo $pids
}
pids=`getpids $appname`
# kill all apps all in one
if [ -n "$pids" ] ; then
kill -9 $pids
fi
# Or you can kill app one by one
kill_app() {
local apppid=$1
#if app_pid exists, kill the process
if [ -n "$appid" ] ; then
kill -9 $appid
sleep 1
fi
}
for appid in $pids;
do
echo "PID=$appid"
kill_app $appid
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment