#!/bin/bash
# to kill process that port already used
# ./kill_port.sh 8080
index=1
if [ ! -n "$1" ] ;then
echo "do nothing!"
else
for var in $(echo $(netstat -pln | grep tcp | grep :$1))
do
if [ `expr $index % 7` == 0 ]
then
array=(${var//\// })
if [ ${#array[*]} == 2 ]
then
echo "kill process, id=${var}"
kill -9 ${array[0]}
fi
fi
index=`expr $index + 1`
done
fi