Determine the process pid listening on a certain port

前端 未结 8 1727
孤城傲影
孤城傲影 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条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 00:08

    The -p flag of netstat gives you PID of the process:

    netstat -l -p
    

    Edit: The command that is needed to get PIDs of socket users in FreeBSD is sockstat. As we worked out during the discussion with @Cyclone, the line that does the job is:

    sockstat -4 -l | grep :80 | awk '{print $3}' | head -1
    

提交回复
热议问题