zoukankan      html  css  js  c++  java
  • linux如何查看端口被谁占用

    1、查看端口是否被占用

    [guosong@alice48 main]$ netstat -nlp|grep 6184 
    (Not all processes could be identified, non-owned process info
    will not be shown, you would have to be root to see it all.)
    tcp 0 0 0.0.0.0:6184 0.0.0.0:* LISTEN 32429/python26
    

      

    man netstat 
      --numeric , -n
           Show numerical addresses instead of trying to determine symbolic host, port or user names.
       -l, --listening
           Show only listening sockets.  (These are omitted by default.)
    
       -p, --program
           Show the PID and name of the program to which each socket belongs.
    

    加了-p参数,可以看到PID

    或者通过lsof查看对应的PID

    [guosong@alice48 main]$ lsof -i tcp:6184
    COMMAND    PID    USER   FD   TYPE     DEVICE SIZE NODE NAME
    python26 32429 guosong   39u  IPv4 2261894200       TCP *:6184 (LISTEN)
    
           -i [i]   This option selects the listing of files any of whose Internet address matches the address specified  in  i.   If  no address is specified, this option selects the listing of all Internet and
                    x.25 (HP-UX) network files.
                    [46][protocol][@hostname|hostaddr][:service|port]
    
                    where:
                         46 specifies the IP version, IPv4 or IPv6
                              that applies to the following address.
                              ’6’ may be be specified only if the UNIX
                              dialect supports IPv6.  If neither ’4’ nor
                              ’6’ is specified, the following address
                              applies to all IP versions.
                         protocol is a protocol name - TCP or UDP.
    

    2、查看命令路径

    获取到PID后,通过ps查看进程命令

    [guosong@alice48 main]$ ps aux |grep 32429
    guosong   3737  0.0  0.0  61160   744 pts/31   S+   16:22   0:00 grep 32429
    guosong  32429  0.6  0.1 234940 20860 pts/31   S    16:14   0:03 python26 api_main.py
    
    [guosong@alice48 ~]$ readlink /proc/32429/exe 
    /usr/bin/python26
    

    通过readlink也只是知道这是个python26的脚本,至于后面api_main.py的绝对路径应该怎么找呢??

    [guosong@alice48 32429]$ readlink /proc/32429/cwd
    /usr/home/guosong/mysqlapi/main

     http://www.blogjava.net/kxx129/archive/2013/05/13/399206.html

     

  • 相关阅读:
    121. 122. 123. 188. Best Time to Buy and Sell Stock *HARD* 309. Best Time to Buy and Sell Stock with Cooldown -- 买卖股票
    from __future__ import absolute_import
    sql之left join、right join、inner join的区别
    Eclipse workspace 被占用问题
    JavaScript SetInterval与setTimeout使用方法详解
    提示框3秒钟后自动消失
    页面加载及取消加载
    分层总结
    java中的注释
    canvas画图
  • 原文地址:https://www.cnblogs.com/gsblog/p/3778134.html
Copyright © 2011-2022 走看看