简体   繁体   English

如何查找和取消绑定的套接字

[英]How to Find and Unlink a Bound Socket

I get a "bind: Address already in use" error. 我收到“绑定:地址已在使用中”错误。 Is there any way to find which socket is bound? 有什么方法可以找到绑定哪个套接字? When I find it, how to I unlink it? 找到后,如何取消链接?

A socket is binded to a process. 套接字绑定到进程。 You just need to find that process id using: 您只需要使用以下命令找到该进程ID:

netstat -nap

The -p flag will include the process id but you have to be root -p标志将包含进程ID, 但您必须是root用户

tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 11152/lighttpd

In this example port 8080 is assigned to lighttpd, process id 11152 在此示例中,端口8080被分配给lighttpd,进程ID 11152

The command to list files opened by processes (lsof) will give similar information 列出由进程(lsof)打开的文件的命令将提供类似的信息

Once you found the process id, you can simply kill it by issuing: 找到进程ID后,只需发出以下命令即可将其杀死:

kill [pid]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM