lsof -i 需要 root 用户的权限来执行

  1. $ lsof -i:8000
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. nodejs 26993 root 10u IPv4 37999514 0t0 TCP *:8000 (LISTEN)

netstat -tunlp 用于显示 tcp,udp 的端口和进程等相关情况。

  1. $ netstat -tunlp | grep 8000
  2. tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 26993/nodejs
  3. $ netstat -tunlp | grep bystackd
  4. tcp6 0 0 :::9889 :::* LISTEN 3890567/bystackd
  5. tcp6 0 0 :::56658 :::* LISTEN 3890567/bystackd
  6. udp 0 0 0.0.0.0:5353 0.0.0.0:* 3890567/bystackd
  7. udp 0 0 0.0.0.0:5353 0.0.0.0:* 3890567/bystackd
  8. udp6 0 0 :::56658 :::* 3890567/bystackd
  9. udp6 0 0 :::5353 :::* 3890567/bystackd
  10. udp6 0 0 :::5353 :::* 3890567/bystackd

参考:

Linux 查看端口占用情况