查看某个端口被占用的进程
netstat
netstat -pan
可用于查看当前开放的端口和正在进行的网络连接。
$ netstat -pan
查看某端口被哪个进程占用:
$ netstat -pan | grep ":<端口号>"
如:
$ sudo netstat -pan | grep ":80"
可以看到当前80端口被
httpd
(即Apache Web Server)占用.
lsof
# 查看某个端口是否被占用
$ lsof -i:[端口号]
# e.g.
$ sudo lsof -i:22
查看当前被占用的所有端口
netstat
$ netstat -at | grep LISTEN
# Or
$ sudo netstat -tulpn | grep LISTEN
lsof
$ lsof -i -P | grep -i "listen"
# Or
$ sudo lsof -i -P -n | grep LISTEN
查看特定进程占用的所有端口
$ netstat -anp | grep <pid>
$ netstat -nltp | grep <pid>
杀死特定端口上运行的进程
$ kill -9 `lsof -i:8081 | grep LISTEN | awk '{print $2}'`
Reference
FEATURED TAGS
algorithm
algorithmproblem
architecturalpattern
architecture
aws
c#
cachesystem
codis
compile
concurrentcontrol
database
dataformat
datastructure
debug
design
designpattern
distributedsystem
django
docker
domain
engineering
freebsd
git
golang
grafana
hackintosh
hadoop
hardware
hexo
http
hugo
ios
iot
java
javaee
javascript
kafka
kubernetes
linux
linuxcommand
linuxio
lock
macos
markdown
microservices
mysql
nas
network
networkprogramming
nginx
node.js
npm
oop
openwrt
operatingsystem
padavan
performance
programming
prometheus
protobuf
python
redis
router
security
shell
software testing
spring
sql
systemdesign
truenas
ubuntu
vmware
vpn
windows
wmware
wordpress
xml
zookeeper