发现项目端口号被占用时如何解决(我的项目是react项目,默认开启的服务器端口是4000端口)
1.lsOf -i:端口号
【则会显示占用这个端口号的进程,会有其类型和进程号】
2. kill 进程号
来杀掉这些进程
(我的终端记录如下:)
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:40:34] C:130
$ lsOf -i:4000 【查看是什么进程占用了项目要用到的端口】
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2671 panweixuan 26u IPv6 0x7a23eede5e02d7f7 0t0 TCP *:terabase (LISTEN)
Google 4441 panweixuan 30u IPv4 0x7a23eede675181b7 0t0 TCP localhost:54395->localhost:terabase (ESTABLISHED)
Google 4441 panweixuan 31u IPv4 0x7a23eede5f7b2eb7 0t0 TCP localhost:54396->localhost:terabase (ESTABLISHED)
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:40:41]
$ kill 2671 【杀掉该进程】
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:40:51]
$ kill 4441
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:40:56]
$ lsOf -i:4000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 2671 panweixuan 26u IPv6 0x7a23eede5e02d7f7 0t0 TCP *:terabase (LISTEN)
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:41:00]
$ lsOf -i:4000
panweixuan @ bogon in ~/Documents/code/media/agency on git:feature/feature/fe-agency-edit-3 x [14:41:43] C:1
$ npm run start
3. 若命令行杀不死进程的,手动除掉:
打开活动监视器(我的电脑是mac的),找到该进程,强制退出。【注意找准的是进程号】
小TIPS:可先搜索进程的类型来缩小寻找的范围
网友评论