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

     

  • 相关阅读:
    秋雨梧桐的大门
    期望题选做
    二维线段树->树套树
    二维线段树
    树的重心的应用
    处置固定资产的收到的现金属于投资活动的现金
    分期付款购入固定资产 属于投资还是筹资
    退休金计入管理费用,不计入支付的其他与经营活动相关的现金
    购买商品,接受劳务支付的现金
    在建工程人员薪酬,计入“在建工程”科目
  • 原文地址:https://www.cnblogs.com/gsblog/p/3778134.html
Copyright © 2011-2022 走看看