zoukankan      html  css  js  c++  java
  • linux中根据进程名查端口号(或根据端口号查看进程名)

    大家在Linux系统中排查问题,经常会遇到根据进程名查端口号,或者根据端口号查进程名,下边针对这两种情况总结一下:
    一,根据进程名查对应的端口号

    netstat -tlnp | grep processname
    

    二,根据端口号查对应的进程名
    (一)使用lsof命令,以查找占用端口80为例,用法如下:

    [root@localhost sbin]# lsof -i:80
    COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   8246   root    6u  IPv4  64233      0t0  TCP *:http (LISTEN)
    nginx   8247 nobody    6u  IPv4  64233      0t0  TCP *:http (LISTEN)
    [root@localhost sbin]# 
    

    (二)使用netstat命令,以查找占用80端口为例,用法如下:

    [root@localhost sbin]# netstat -nlp|grep :80
    tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      8246/nginx          
    [root@localhost sbin]# 
    

    (三)使用ps命令,可以查看已知进程PID的执行目录的详细信息

    [root@localhost sbin]# ps -ef | grep 8246
    root       8246      1  0 14:56 ?        00:00:00 nginx: master process ./nginx
    nobody     8247   8246  0 14:56 ?        00:00:00 nginx: worker process
    root       8461   2679  0 15:26 pts/1    00:00:00 grep 8246
    [root@localhost sbin]# ps -x | grep 8246  
    Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
      8246 ?        Ss     0:00 nginx: master process ./nginx
      8463 pts/1    S+     0:00 grep 8246
    [root@localhost sbin]# 
    

    本文来自博客园,作者:老吉来了,转载请注明原文链接:https://www.cnblogs.com/carlos-zhou/p/15531574.html

  • 相关阅读:
    HDU 5213 分块 容斥
    HDU 2298 三分
    HDU 5144 三分
    HDU 5145 分块 莫队
    HDU 3938 并查集
    HDU 3926 并查集 图同构简单判断 STL
    POJ 2431 优先队列
    HDU 1811 拓扑排序 并查集
    HDU 2685 GCD推导
    HDU 4496 并查集 逆向思维
  • 原文地址:https://www.cnblogs.com/carlos-zhou/p/15531574.html
Copyright © 2011-2022 走看看