zoukankan      html  css  js  c++  java
  • 在线关闭 CLOSE_WAIT状态TCP连接

    1、查看某个端口的所有TCP连接:

    [root@Centos projects]# netstat -anp | grep 8087
    tcp6       0      0 :::8087                 :::*                    LISTEN      4931/java           
    tcp6       1      0 192.168.229.140:8087    192.168.229.1:10664     CLOSE_WAIT  4931/java           
    tcp6       1      0 192.168.229.140:8087    192.168.229.1:10665     CLOSE_WAIT  4931/java           
    tcp6       1      0 192.168.229.140:8087    192.168.229.1:10671     CLOSE_WAIT  4931/java           
    tcp6       1      0 192.168.229.140:8087    192.168.229.1:10668     CLOSE_WAIT  4931/java           
    tcp6       1      0 192.168.229.140:8087    192.168.229.1:10670     CLOSE_WAIT  4931/java           
    [root@Centos projects]# 

    2、获取 CLOSE_WAIT 状态连接的文件描述符:

    [root@Centos projects]# lsof -np 4931 | grep "CLOSE_WAIT"
    java    4931 root   27u     IPv6              75515       0t0      TCP 192.168.229.140:simplifymedia->192.168.229.1:10764 (CLOSE_WAIT)
    java    4931 root   28u     IPv6              75516       0t0      TCP 192.168.229.140:simplifymedia->192.168.229.1:10765 (CLOSE_WAIT)
    java    4931 root   30u     IPv6              75517       0t0      TCP 192.168.229.140:simplifymedia->192.168.229.1:10768 (CLOSE_WAIT)
    java    4931 root   31u     IPv6              75518       0t0      TCP 192.168.229.140:simplifymedia->192.168.229.1:10769 (CLOSE_WAIT)
    java    4931 root   33u     IPv6              75183       0t0      TCP 192.168.229.140:simplifymedia->192.168.229.1:10763 (CLOSE_WAIT)
    [root@Centos projects]# lsof -np 4931 | grep "CLOSE_WAIT" | awk '{print $4}'
    27u
    28u
    30u
    31u
    33u
    [root@Centos projects]# 

    3、使用GDB关闭 CLOSE_WAIT状态连接:

    [root@Centos projects]# gdb -p 4931  # 连接到 4931 进程
    GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "x86_64-redhat-linux-gnu".
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Attaching to process 4931
    ...(略去内容)...
    (gdb)           # 这里为 gdb 命令提示符

    然后根据文件描述符关闭指定的 socket 连接:

    (gdb) call close(27u)  # 27u即 close_wait 状态连接的文件描述符
    ...(略去内容)...
    艺无止境,诚惶诚恐, 感谢开源贡献者的努力!!
  • 相关阅读:
    再谈加密-RSA非对称加密的理解和使用
    WEB开发中的字符集和编码
    网页实时聊天之PHP实现websocket
    PHP中的回调函数和匿名函数
    shell实现SSH自动登陆
    初探PHP多进程
    PHP的openssl加密扩展使用小结
    搭建自己的PHP框架心得(三)
    docker 快速搭建Nexus3
    用图形数据库Neo4j 设计权限模块
  • 原文地址:https://www.cnblogs.com/d0usr/p/11836502.html
Copyright © 2011-2022 走看看