有时候需要根据运行的端口号查询进程的Pid,可以使用lsof命令查询。

根据端口获得进程号

lsof -i :8080 | grep -i LISTEN | awk '{print $2}'

组合获得该进程的执行命令

lsof -i :8080 | grep -i LISTEN | awk '{print $2}' | xargs -I {} ps -o command -p {} | tail -n +2

管道给kill掉该进程

lsof -i :8080 | grep -i LISTEN | awk '{print $2}' | xargs -I {} kill -15 {}

相关文章:

  • 2022-12-23
  • 2021-11-18
  • 2021-11-08
  • 2022-12-23
  • 2021-11-18
  • 2021-11-02
  • 2021-08-28
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2021-12-27
  • 2021-07-03
  • 2022-02-02
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案