zoukankan      html  css  js  c++  java
  • 【Problems】端口被占用 查看是被谁占用并关闭它

    文章目录

    经常在Windows、Linux环境下运行JavaWeb项目,Tomcat的端口被占用了。
    端口被占用就查看是被谁占用关闭它就行。

    Windows

    在Windows上运行JavaWeb项目提示Tomcat端口被占用了。

    Description:

    The Tomcat connector configured to listen on port 8010 failed to start. The port may already be in use or the connector may be misconfigured.

    Action:

    Verify the connector’s configuration, identify and stop any process that’s listening on port 8010, or configure this application to listen on another port.

    查看某个端口被谁占用并强制关闭它。

    打开cmd,输入netstat -ano,列出所有端口的情况。观察被占用的端口,找到查看被占用端口对应的PID(一行的最后)。

    在这里插入图片描述

    或者直接输入命令+端口号:netstat -aon|findstr “8081”回车查看到PID

    在这里插入图片描述

    我这里PID是76312。

    输入tasklist|findstr “76312”,回车,查看是哪个进程或者程序占用了8010端口的。

    在这里插入图片描述

    是java.exe,

    可以打开任务管理器,在详细信息的PID一列查看76312对应的进程右键结束任务。

    在这里插入图片描述

    或者直接taskkill /pid 76312 -f 强制关闭。

    在这里插入图片描述

    小结:

    netstat -aon|findstr “8081” 查看端口被谁占用的命令。

    taskkill是Windows命令行里终止指定程序“进程”的命令。

    taskkill /pid 76312 -f

    taskkill /im java.exe -f

    /f 表示强制终止
    /im 表示指定的进程名称,例如“java.exe"

    /pid 表示指定的进程ID进程号

    在这里插入图片描述

    Linux

    运行个JavaWeb的程序。

    java -jar school.jar
    

    运行错误出现下面提示信息。


    APPLICATION FAILED TO START


    Description:

    Web server failed to start. Port 8001 was already in use.

    Action:

    Identify and stop the process that’s listening on port 8001 or configure this application to listen on another port.

    端口8001被占用了。。。应该是之前运行了。

    [root@liuawen school]# netstat -anp | grep 8001
    tcp        0      0 0.0.0.0:8001            0.0.0.0:*               LISTEN      19453/java          
    [root@liuawen school]# kill -9 19453
    [root@liuawen school]# netstat -anp | grep 8001
    [root@liuawen school]# ps -ef | grep 8001
    root     19625 19501  0 11:08 pts/2    00:00:00 grep --color=auto 8001
    
    

    kill -9 进程号 杀掉占用端口的进程

  • 相关阅读:
    POJ 1330 Nearest Common Ancestors(LCA Tarjan算法)
    LCA 最近公共祖先 (模板)
    线段树,最大值查询位置
    带权并查集
    转负二进制
    UVA 11437 Triangle Fun
    UVA 11488 Hyper Prefix Sets (字典树)
    UVALive 3295 Counting Triangles
    POJ 2752 Seek the Name, Seek the Fame (KMP)
    UVA 11584 Partitioning by Palindromes (字符串区间dp)
  • 原文地址:https://www.cnblogs.com/liuawen/p/12854019.html
Copyright © 2011-2022 走看看