如何删除CLOSE_WAIT套接字连接 [英] How do I remove a CLOSE_WAIT socket connection
问题描述
我写了一个小程序,可以在特定端口上与服务器交互.该程序可以正常运行,但是:
I have written a small program that interacts with a server on a specific port. The program works fine, but:
一旦程序意外终止,并且此套接字连接一直以CLOSE_WAIT
状态显示.如果我尝试运行程序,则该程序将挂起,并且必须强制将其关闭,这甚至会累积更多 CLOSE_WAIT
套接字连接.
Once the program terminated unexpectedly, and ever since that socket connection is shown in CLOSE_WAIT
state. If I try to run a program it hangs and I have to force it close, which accumulates even more CLOSE_WAIT
socket connections.
有没有一种方法可以清除这些连接?
Is there a way to flush these connections?
推荐答案
CLOSE_WAIT
表示您的程序仍在运行,并且尚未关闭套接字(内核正在等待这样做).将-p
添加到netstat
以获取该pid,然后更加有力地将其杀死(如果需要,可以使用SIGKILL
).那应该摆脱您的CLOSE_WAIT
套接字.您还可以使用ps
查找pid.
CLOSE_WAIT
means your program is still running, and hasn't closed the socket (and the kernel is waiting for it to do so). Add -p
to netstat
to get the pid, and then kill it more forcefully (with SIGKILL
if needed). That should get rid of your CLOSE_WAIT
sockets. You can also use ps
to find the pid.
SO_REUSEADDR
用于服务器和TIME_WAIT
套接字,因此不适用于此处.
SO_REUSEADDR
is for servers and TIME_WAIT
sockets, so doesn't apply here.
这篇关于如何删除CLOSE_WAIT套接字连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!