Skip to content

Instantly share code, notes, and snippets.

@axetroy
Last active April 21, 2019 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axetroy/0f0da7420f303ec2b5421ae2ff91092e to your computer and use it in GitHub Desktop.
Save axetroy/0f0da7420f303ec2b5421ae2ff91092e to your computer and use it in GitHub Desktop.
跨平台,关闭xxx端口

有些时候程序开启了http服务,监听了某个端口。

然后关闭终端或者CTRL+C退出之后,进程没有被杀掉,端口还在监听,导致下次启动的时候报错。

这里就记录下来,查看进程监听的端口,以及杀死进程

Window

# 查看各进程监听的端口
netstat -a -n -o

### 找到对应的进程id之后
taskkill /pid {{进程id}} /t /f

Linux

netstat -pan -a | grep 3000
kill 3000

跨平台

npm install find-process -g
find-process -h # 查看

# 或者
npm install @axetroy/kp -g
kp 3000 # kill the process which listen on 3000 port
@huyansheng3
Copy link

lsof -i:port 这样也可以, list open file,跟 linux 的文件系统契合。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment