Skip to content

Instantly share code, notes, and snippets.

@skyhisi
Created August 6, 2019 12:11
Show Gist options
  • Save skyhisi/6fe6f76c640d3294dbd2d91db2723479 to your computer and use it in GitHub Desktop.
Save skyhisi/6fe6f76c640d3294dbd2d91db2723479 to your computer and use it in GitHub Desktop.
Script to kill postgres workers for a given process
#!/bin/bash
PGPORT=5678
APP_PID=$(pidof -s $1)
if [ $? -ne "0" ]
then
echo "Can not find PID of $1"
exit 1
fi
function getpgpids()
{
for port in $(netstat -npt | grep "$PGPORT"'.*'"$1/" | tr -s ' ' | cut -d ' ' -f4 | cut -c5-)
do
ps -u postgres u | grep $port
done | tr -s ' ' | cut -d ' ' -f 2 | sort
}
for pgpid in $(getpgpids $APP_PID)
do
echo "Killing PID $pgpid"
kill $pgpid
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment