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 状态连接的文件描述符
    ...(略去内容)...
    艺无止境,诚惶诚恐, 感谢开源贡献者的努力!!
  • 相关阅读:
    4-MSP430定时器_定时器中断
    关于STM32的外部引脚中断的问题
    关于stm32的正交解码
    红外接收控制灯亮灭
    mack pro常用快捷键
    liunx操作系统安装<一>
    支付宝架构师:从工程师到架构师的成长之路
    maven之setting.xml的配置详解
    分布式之《保证分布式系统数据一致性的6种解决方案》
    Eclipse中jsp、js文件编辑时,卡死现象解决汇总
  • 原文地址:https://www.cnblogs.com/d0usr/p/11836502.html
Copyright © 2011-2022 走看看