`
javasogo
  • 浏览: 1813005 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

如何在Window或Linux/Unix中查找并干掉占用指定端口的进程

 
阅读更多

Windows

netstat /?

Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]

  -a            Displays all connections and listening ports.
  -b            Displays the executable involved in creating each connection or
                listening port. In some cases well-known executables host
                multiple independent components, and in these cases the
                sequence of components involved in creating the connection
                or listening port is displayed. In this case the executable
                name is in [] at the bottom, on top is the component it called,
                and so forth until TCP/IP was reached. Note that this option
                can be time-consuming and will fail unless you have sufficient
                permissions.
  -e            Displays Ethernet statistics. This may be combined with the -s
                option.
  -n            Displays addresses and port numbers in numerical form.
  -o            Displays the owning process ID associated with each connection.
  -p proto      Shows connections for the protocol specified by proto; proto
                may be any of: TCP, UDP, TCPv6, or UDPv6.  If used with the -s
                option to display per-protocol statistics, proto may be any of:
                IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, or UDPv6.
  -r            Displays the routing table.
  -s            Displays per-protocol statistics.  By default, statistics are
                shown for IP, IPv6, ICMP, ICMPv6, TCP, TCPv6, UDP, and UDPv6;
                the -p option may be used to specify a subset of the default.
  -v            When used in conjunction with -b, will display sequence of
                components involved in creating the connection or listening
                port for all executables.
  interval      Redisplays selected statistics, pausing interval seconds
                between each display.  Press CTRL+C to stop redisplaying
                statistics.  If omitted, netstat will print the current
                configuration information once.

netstat -o

  Proto  Local Address          Foreign Address        State           PID
  ...
  TCP    IXX-L3YWERK:3521       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3522       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3524       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3525       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3526       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3527       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3528       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3529       localhost:3306         ESTABLISHED     5892
  TCP    IXX-L3YWERK:3530       localhost:3306         ESTABLISHED     5892
  ...

taskkill /?

TASKKILL [/S system [/U username [/P [password]]]]
         { [/FI filter] [/PID processid | /IM imagename] } [/F] [/T]

Description:
    This command line tool can be used to end one or more processes.
    Processes can be killed by the process id or image name.

Parameter List:
    /S    system           Specifies the remote system to connect to.

    /U    [domain/]user    Specifies the user context under which
                           the command should execute.

    /P    [password]       Specifies the password for the given
                           user context. Prompts for input if omitted.

    /F                     Specifies to forcefully terminate
                           process(es).

    /FI   filter           Displays a set of tasks that match a
                           given criteria specified by the filter.

    /PID  process id       Specifies the PID of the process that
                           has to be terminated.

    /IM   image name       Specifies the image name of the process
                           that has to be terminated. Wildcard '*'
                           can be used to specify all image names.

    /T                     Tree kill: terminates the specified process
                           and any child processes which were started by it.

    /?                     Displays this help/usage.

Filters:
    Filter Name   Valid Operators           Valid Value(s)
    -----------   ---------------           --------------
    STATUS        eq, ne                    RUNNING | NOT RESPONDING
    IMAGENAME     eq, ne                    Image name
    PID           eq, ne, gt, lt, ge, le    PID value
    SESSION       eq, ne, gt, lt, ge, le    Session number.
    CPUTIME       eq, ne, gt, lt, ge, le    CPU time in the format
                                            of hh:mm:ss.
                                            hh - hours,
                                            mm - minutes, ss - seconds
    MEMUSAGE      eq, ne, gt, lt, ge, le    Memory usage in KB
    USERNAME      eq, ne                    User name in [domain/]user
                                            format
    MODULES       eq, ne                    DLL name
    SERVICES      eq, ne                    Service name
    WINDOWTITLE   eq, ne                    Window title

NOTE: Wildcard '*' for the /IM switch is accepted only with filters.

NOTE: Termination of remote processes will always be done forcefully
      irrespective of whether /F option is specified or not.

Examples:
    TASKKILL /S system /F /IM notepad.exe /T
    TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
    TASKKILL /F /IM notepad.exe /IM mspaint.exe
    TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
    TASKKILL /F /FI "USERNAME eq NT AUTHORITY/SYSTEM" /IM notepad.exe
    TASKKILL /S system /U domain/username /FI "USERNAME ne NT*" /IM *
    TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

除了使用taskkill外,还可以通过快捷键Ctrl + Shift + Esc打开任务管理器,在它的“Process”或“进程”页签下找到对应的PID来结束任务!

Linux/Unix

netstat --help

usage: netstat [-vWeenNcCF] [] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [ ...]
       netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }

        -r, --route              display routing table
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections

        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresses
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -c, --continuous         continuous listing

        -l, --listening          display listening server sockets
        -a, --all, --listening   display all sockets (default: connected)
        -o, --timers             display timers
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB

  ={-t|--tcp} {-u|--udp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
  =Use '-6|-4' or '-A ' or '--'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
    x25 (CCITT X.25)

netstat -lp

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
...
tcp        0      0 *:amandaidx             *:*                     LISTEN      -
tcp        0      0 localhost:amidxtape     *:*                     LISTEN      -
tcp        0      0 *:8808                  *:*                     LISTEN      -
tcp        0      0 PKG-LOCAL-SERVER.:mysql *:*                     LISTEN      -
tcp        0      0 localhost:submission    *:*                     LISTEN      -
tcp        0      0 *:netbios-ssn           *:*                     LISTEN      -
tcp        0      0 *:www                   *:*                     LISTEN      -
tcp        0      0 *:50001                 *:*                     LISTEN      -
tcp        0      0 *:ssh                   *:*                     LISTEN      -
tcp        0      0 localhost:ipp           *:*                     LISTEN      -
tcp        0      0 localhost:smtp          *:*                     LISTEN      -
...

kill

kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

使用man kill可以取得详细说明

分享到:
评论

相关推荐

    Linux/window下怎样查看某个端口被哪个程序/进程占用

    在IT系统管理中,了解哪些程序或进程正在占用特定端口是至关重要的,这有助于诊断网络问题、优化资源分配和防止安全威胁。本篇将详细讲解在Linux和Windows操作系统下如何查看并管理占用端口的程序。 在Windows系统...

    window下查看哪个端口被哪个进程占用着_查看占用端口的进程

    总之,通过`netstat`和`tasklist`命令,我们可以有效地在Windows系统中查找并识别占用特定端口的进程。这对于故障排查、性能监控以及软件配置都至关重要。同时,理解端口的运作原理对于任何IT专业人员来说都是必备的...

    xming专业linux/unix GUI工具

    Xming是一款强大的开源软件,它允许Windows用户在本地操作系统上运行远程Linux或Unix系统的图形用户界面(GUI)。这个工具为那些无法或者不想在Linux服务器上配置图形环境的用户提供了一个便捷的解决方案。Xming的...

    tty_Linux/Unix编程_

    在Linux和Unix操作系统中,TTY(Teletype)是一种历史悠久的终端设备,它在现代已经演变为对控制台和各种类型的文本终端的抽象。TTY驱动程序是操作系统内核的一部分,负责处理与这些设备的交互。本教程将深入探讨TTY...

    Windows下80端口被进程System占用的解决方法亲测可用.docx

    在上述命令中,我们可以看到80端口被System进程占用。那么,为什么System进程会占用80端口呢?这是因为System进程是Windows系统的一个核心进程,它负责管理系统的各种资源。有时,System进程可能会占用80端口,以便...

    Window通过cmd查看端口占用、相应进程、杀死进程等的命令.docx

    - `findstr "指定端口号"`: 在输出结果中查找指定端口号。 **举例**: 如果我们要查找8080端口被哪个进程占用,则可以执行以下命令: ``` C:\> netstat -ano | findstr 8080 ``` 命令执行后,将返回占用8080端口的...

    linux/unix GTK 入门导引

    《Linux/Unix GTK 入门导引》 GTK(GIMP Toolkit)起源于GIMP(General Image Manipulation Program)项目的开发工具集。GTK构建在GDK(GIMP Drawing Kit)之上,它对Xlib的功能进行了封装,使得程序员可以更方便地...

    window.rar_Linux/Unix编程_Unix_Linux_

    标题中的"window.rar_Linux/Unix编程_Unix_Linux_"暗示了这个压缩包可能包含了与在Linux或Unix系统上进行编程相关的资源,特别是与Windows环境有关的移植或跨平台编程内容。描述中提到的"HANDLE WINAPI ...

    Linux+GUI+编程示例入门必备.zip_GUI编程_Linux/Unix编程_linux gui_linux gui程序_

    在IT行业中,Linux GUI编程是开发跨平台应用程序的关键领域,特别是在需要用户友好界面的系统工具或应用程序中。本文将深入探讨Linux GUI编程的基础知识,帮助初学者快速入门。 首先,让我们理解“Linux GUI”是...

    Linux/Unix远程工具window上使用 SecureCRT_CN_6.6.1

    SecureCRT是最常用的终端仿真程序,是windows下登录UNIX或Liunx服务器主机的软件。绿色版本,直接解压即可用。WinSCP是一个Windows环境下使用SSH的开源图形化SFTP客户端。同时支持SCP协议。它的主要功能就是在本地与...

    UNIX/Linux 系统管理技术手册(第四版)

    ### UNIX/Linux系统管理技术手册(第四版)知识点总结 #### 一、书籍概述 《UNIX/Linux系统管理技术手册(第四版)》(简称ULAHv4)是Evi Nemeth等作者共同编著的一本权威指南,旨在为读者提供全面且深入的UNIX/Linux...

    PortTalk 2.2 ——window中中 XP/2000系统中IO端口操作工具

    PortTalk ——window中中 XP/2000系统中IO端口操作工具 PortTalk ——window中中 XP/2000系统中IO端口操作工具 PortTalk ——window中中 XP/2000系统中IO端口操作工具

    grutables.rar_Linux/Unix编程_Unix_Linux_

    2. **设备节点**:在Linux/Unix中,设备通过设备节点(dev文件)与用户空间通信。GRU驱动可能会创建一个或多个设备节点,供应用程序访问。 3. **中断处理**:设备操作可能由硬件中断触发,驱动程序需要注册中断处理...

    WallpaperInfo.rar_Linux/Unix编程_Unix_Linux_

    在Linux/Unix中,进程可以通过管道、套接字、信号量、共享内存等方式进行通信。理解这些机制对于编写高效的服务至关重要。 5. **系统调用**:Linux和Unix提供了丰富的系统调用接口,如`open()`, `read()`, `write()...

    SVGFETurbulence.rar_Linux/Unix编程_Unix_Linux_

    本文将深入探讨在Linux/Unix环境下进行编程的关键知识点,并结合SVG FE Turbulence源代码来解析其在图形处理和接口驱动开发中的应用。 首先,让我们了解一下SVG(Scalable Vector Graphics)FE Turbulence。SVG是一...

    FocusController.rar_Linux/Unix编程_Unix_Linux_

    2. **设备文件**:在Linux/Unix中,硬件设备通常被表示为文件,通过读写操作进行交互。Focus Controller可能会涉及 `/dev/input/*` 目录下的设备文件,这些文件对应着系统的输入设备。 3. **信号量和互斥锁**:用于...

    GraphicsContextCairoWin.rar_Linux/Unix编程_Unix_Linux_

    在Unix/Linux编程中,Cairo库通常用于创建高质量的矢量图形,如GUI应用程序的界面元素、PDF文档、SVG图像或者X Window System上的窗口内容。Cairo支持多种输出后端,包括像素缓冲区、PDF、PostScript、SVG、X11和Win...

    端口占用查询工具(windows)

    端口占用查询工具(windows),查询端口占用。 TCPView is a Windows program that will show you detailed listings of all TCP and UDP endpoints on your system, including the local and remote addresses and ...

    windows 查询占用网络端口的进程PID以及获取进程信息(API开发)

    开发环境window10+VS2012(也...功能就是不需要通过繁琐的命令查看被占用的端口,可通过调用windows API 代码实现,主要API :GetExtendedTcpTable、GetExtendedUdpTable、CreateToolhelp32Snapshot、Module32First等实现

Global site tag (gtag.js) - Google Analytics