You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux环境下Port 80被占用,如何终止该端口上的运行进程?

Fixing "Port 80 in use" on Linux: Kill the Occupying Process

Hey there! Let's get that port 80 freed up so you can run your service. Here's a step-by-step breakdown to track down and terminate the process using it:

Step 1: Find which process is using port 80

Port 80 is a privileged port, so you'll need sudo to see full details. You can use either of these two common tools:

Option 1: Use lsof (most widely available)

Run this command to list all processes tied to port 80:

sudo lsof -i :80

Look for the PID column in the output—this is the process ID you'll need later. The COMMAND column will also tell you what the process is (e.g., nginx, apache2, or a random binary).

Option 2: Use netstat (preinstalled on some older systems)

If lsof isn't available, try netstat with these flags:

sudo netstat -tulpn | grep :80

In the output, the number right before the slash (e.g., 1234/nginx) is the PID.

Step 2: Terminate the process

Once you have the PID, start with a graceful shutdown first—this gives the process a chance to clean up:

kill <PID>

Replace <PID> with the actual number you found (e.g., kill 1234).

If the process refuses to exit, use a force kill command:

kill -9 <PID>

⚠️ Heads up: Force killing can cause data loss if the process was writing to files, so only use this if the graceful kill fails.

Bonus: Stop system-managed services cleanly

If the process is a system service (like Nginx, Apache, or Tomcat), it's safer to use the system's service manager instead of killing the PID directly. For example:

  • For systemd-based systems (most modern Linux distros):
    sudo systemctl stop nginx  # Replace nginx with your service name
    
  • For SysVinit systems:
    sudo service apache2 stop  # Replace apache2 with your service name
    

内容的提问来源于stack exchange,提问作者George G 123

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 04:22:16