Determine the process pid listening on a certain port

前端 未结 8 1752
孤城傲影
孤城傲影 2021-01-29 23:30

As the title says, I\'m running multiple game servers, and every of them has the same name but different PID and the port number. I would

8条回答
  •  旧时难觅i
    2021-01-29 23:58

    I wanted to programmatically -- using only Bash -- kill the process listening on a given port.

    Let's say the port is 8089, then here is how I did it:

    badPid=$(netstat --listening --program --numeric --tcp | grep "::8089" | awk '{print $7}' | awk -F/ '{print $1}' | head -1)
    kill -9 $badPid
    

    I hope this helps someone else! I know it is going to help my team.

提交回复
热议问题