.dotfiles/.config/zsh/functions/fp.zsh

28 lines
725 B
Bash
Raw Permalink Normal View History

2021-01-21 13:40:08 +01:00
#Helps stop processes which use ports
function fp(){
2021-07-14 19:14:02 +02:00
if [ "$(which lsof)" = "lsof not found" ]; then
echo "lsof not installed"
else
for PORT in "$@"
do
if [ "$PORT" != "" ]; then
#echo "checking ($PORT)"
PIDS="$(lsof -t -i:$PORT)"
AMOUNT=$(wc -w<<<$PIDS);
if [ $AMOUNT = 0 ]; then
echo "No processes use port $PORT";
else
echo "Killing $AMOUNT process(es) using port $PORT";
echo "$PIDS" | while IFS= read -r pid ; do
kill -9 $pid;
done
fi
2021-06-22 13:05:12 +02:00
fi
2021-07-14 19:14:02 +02:00
done
fi
2021-06-22 13:05:12 +02:00
}