Linux环境检查哪个端口被占用,例如检查3000端口,另外列出OSX命令如下:
- On linux:
sudo netstat -nltp | grep 3000
- On OSX:
sudo lsof -i -P | grep 3000
通过以上命令可以列出哪些进程占用了这个端口,会显示PID,例如:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8700/nginx
有了PID,可以查询该PID对应的目录,命令如下:
ps -aux|grep 8700
root 8700 0.0 0.0 92136 1948 ? Ss Feb18 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
这样就会列出具体的配置文件,拿到配置文件,可以查看具体配置,命令如下:
more /usr/local/openresty/nginx/conf/nginx.conf