Linux查看进程端口占用

查看所有进程端口

常用:netstat -anp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[netstat -apn](<usage: netstat [-vWeenNcCF] [%3CAf%3E] -r         netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }

-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
-o, --timers display timers
-c, --continuous continuous listing

-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets

<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}
{-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-6|-4' or '-A <af>' or '--<af>'; 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)>)

查看进程

常用:ps -aux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
ps -ef :显示出linux机器所有详细的进程信息
  -e:列出系统所有的进程
  -f:显示UID         PID   PPID  C STIME TTY          TIME CMD 等信息
  -a:显示当前终端下所有的进程,包括其他用户的进程信息
-u:以用户为主的格式显示进程情况
-x:显示所有进程
UID:这个进程是哪个用户执行的
PID:进程的标识号码,用于启停进程
PPID:进程的父进程标识号
C:CPU使用的资源百分比
STIME:进程开始执行的时间
TTY:该进程在哪个终端上执行呢
TIME:该进程使用的CPU总时长
CMD:用户执行某条命令,产生的进行信息

%CPU :显示cpu的百分比使用情况
%MEM:显示内存的百分比使用情况
VSZ:该进程使用的swap内存分区
RSS:进程所占用的内存量
STAT:表示进程此时的状态
  S:终端睡眠中,可以被唤醒
  s:该进程含有子进程
  R:该进程运行中
  D:该进程不可中断睡眠
  T:表示进程已停止
  Z:该进程已经是僵尸进程了(父进程异常崩溃)
  +:前台进程
  N:低优先级进程
  <:高优先级进程
  L:该进程已经被锁定

查看进程端口占用

  1. 查看进程pid:ps -aux找到进程的PID
  2. 查看端口占用:netstat -apn | grep 进程PID