如何删除CLOSE_WAIT套接字连接 [英] How do I remove a CLOSE_WAIT socket connection

查看:637
本文介绍了如何删除CLOSE_WAIT套接字连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小程序,可以在特定端口上与服务器交互.该程序可以正常运行,但是:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆