Determine the process pid listening on a certain port

前端 未结 8 1721
孤城傲影
孤城傲影 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:05

    Since sockstat wasn't natively installed on my machine I hacked up stanwise's answer to use netstat instead..

    netstat -nlp | grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:2000" | awk '{print $7}' | sed -e "s/\/.*//g""
    
    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题