linux mac 端口占用,mac 终端查看端口命令

  • Post author:
  • Post category:linux


查看 端口所在线程 lsof -i:8080

mac-abeen:spider abeen$ lsof -i:8080

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Python 5651 abeen 9u IPv4 0xb1d20b318d3e65ed 0t0 TCP *:http-alt (LISTEN)

Python 5651 abeen 10u IPv6 0xb1d20b3187b23fed 0t0 TCP *:http-alt (LISTEN)

查看mac终端端口命令 netstat -AaLlnW (相当于linux的 netstat -lntp)

mac-abeen:spider abeen$ netstat -AaLlnW

Current listen queue sizes (qlen/incqlen/maxqlen)

Socket Flowhash Listen Local Address

b1d20b319398e96d 0 0/0/1 127.0.0.1.56987

b1d20b3193a0ec6d 0 0/0/128 127.0.0.1.56966

b1d20b318df39fed 0 0/0/1 127.0.0.1.56899

b1d20b31957a896d 0 0/0/10 127.0.0.1.12227

b1d20b31957aa5ed 0 0/0/1 127.0.0.1.56906

b1d20b3193e05fed 0 0/0/10 127.0.0.1.12384

b1d20b3188c06fed 0 0/0/128 127.0.0.1.56882

b1d20b31958bfc6d 0 0/0/1 127.0.0.1.56870

b1d20b3187b23fed 0 0/0/128 *.8080

b1d20b318d3e65ed 0 0/0/128 *.8080

b1d20b3187b22ead 0 0/0/128 *.49204

b1d20b318aea45ed 0 0/0/128 *.49204

b1d20b3187b2232d 0 0/0/70 *.33060

b1d20b3187b228ed 0 0/0/128 *.3306

b1d20b3187b28c6d 0 0/0/128 *.22

b1d20b3187b2346d 0 0/0/128 *.22

查看端口是否被占用

mac-abeen:spider abeen$ sudo lsof -i :8080

Password:

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Python 5651 abeen 9u IPv4 0xb1d20b318d3e65ed 0t0 TCP *:http-alt (LISTEN)

Python 5651 abeen 10u IPv6 0xb1d20b3187b23fed 0t0 TCP *:http-alt (LISTEN)

mac-abeen:spider abeen$ netstat -anp tcp | grep 8080

tcp4 0 0 192.168.0.100.58080 120.221.156.99.443 ESTABLISHED

tcp6 0 0 *.8080 *.* LISTEN

tcp4 0 0 *.8080 *.* LISTEN

结束占用端口的所有进程

lsof -P | grep ‘:8080’ | awk ‘{print $2}’ | xargs kill -9