问题描述
正如标题所述,我正在运行多个游戏服务器,每个服务器都具有相同的name
,但具有不同的PID
和port
编号.我想匹配正在侦听某些端口的服务器的PID
,然后我想终止该过程.我需要它来完成我的bash脚本.
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 like to match the PID
of the server which is listening on certain port, and then I would like to kill this process. I need that in order to complete my bash script.
那有可能吗?因为它尚未在网络上找到任何解决方案.
Is that even possible? Because it didn't find yet any solutions on the web.
推荐答案
netstat
的-p
标志为您提供进程的PID:
The -p
flag of netstat
gives you PID of the process:
netstat -l -p
在FreeBSD中获取套接字用户的PID所需的命令是sockstat
.正如我们在与@Cyclone进行讨论期间所得出的结论一样,执行此操作的行是:
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
这篇关于确定进程pid在特定端口上的侦听的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!