如何删除 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屋!