TechBuzzPro

Find Which Process Is Listening on a Port

· 5 min read · Apps & Browsers

In this article
  1. Why You Need to Identify the Process
  2. How Ports and Processes Work
  3. Finding the Process on Windows
  4. Finding the Process on Linux and macOS
  5. Choosing the Right Tool for Your Situation
  6. Common Problems and How to Fix Them
  7. Frequently Asked Questions

To find which process is listening on a particular port, use the netstat command with the -ano flags on Windows, lsof -i :PORT on macOS and Linux, or ss -tulpn on modern Linux systems. These commands show the process ID (PID) and name associated with each open port, letting you identify and manage the application.

Why You Need to Identify the Process

When a port is already in use, you might see errors like “Address already in use” when starting a web server or database. Knowing which process occupies the port helps you decide whether to stop it, reconfigure your application, or investigate a potential security issue. For example, if port 8080 is unexpectedly occupied, it could be a leftover development server, a malware backdoor, or a legitimate service you forgot about. Identifying the process is the first step in resolving the conflict safely.

How Ports and Processes Work

Every network connection uses a port number (0–65535) to route traffic to the correct application on a machine. When a program starts listening on a port, the operating system assigns it a unique PID. The PID is a number that identifies the running process, and you can use it to get more details about the program, such as its name, executable path, and memory usage. The mapping between ports and PIDs is maintained by the OS kernel and can be queried with command-line tools.

Finding the Process on Windows

Windows provides the built-in netstat utility. Open Command Prompt or PowerShell as Administrator and run:

netstat -ano | findstr :8080

This lists all connections and listening ports that include “8080”. The last column is the PID. To see the process name, use:

tasklist /fi "PID eq 1234"

Replace 1234 with the actual PID. If you prefer a graphical interface, open Resource Monitor (resmon.exe), go to the Network tab, and expand “Listening Ports”. You’ll see the port, PID, and process name. For a more advanced tool, Sysinternals TCPView shows real-time port and process activity.

Finding the Process on Linux and macOS

On Linux, ss is the modern replacement for netstat. Run:

ss -tulpn | grep :8080

The -p flag shows the process name and PID, but requires root privileges to see processes owned by other users. If ss isn’t available, use netstat -tulpn. On macOS, the lsof command is the standard:

lsof -i :8080

This outputs the command name, PID, and user. To get more detail about the process, use ps -p PID. On older macOS versions, netstat -anv can also show the PID, but lsof is simpler.

Choosing the Right Tool for Your Situation

Your choice depends on your OS and what you need to do:

  • Quick check on Windows: netstat -ano
  • Graphical view on Windows: Resource Monitor or TCPView
  • Linux with ss: ss -tulpn (fast, detailed)
  • macOS and Linux with lsof: lsof -i :port (works on both)
  • When you only need the PID: netstat -ano (Windows) or lsof -t -i :port (Linux/macOS)

For scripting, lsof -t -i :port returns just the PID, which you can pass to kill or ps. On Windows, you can use PowerShell’s Get-NetTCPConnection -LocalPort 8080 to get the PID, then Get-Process -Id for the name.

Common Problems and How to Fix Them

If you get “Access denied” when running ss -p or lsof, you need to run the command with sudo (Linux/macOS) or as Administrator (Windows). If the port doesn’t appear in the output, it might be closed or filtered by a firewall, meaning no process is listening. If you see multiple PIDs for the same port, that’s unusual; one process typically owns a port, but a process can have multiple sockets. If you identify a process you don’t recognize, look it up online before killing it, as some system services are essential. To free the port, you can stop the process gracefully (e.g., kill PID on Linux/macOS, taskkill /PID PID /F on Windows) or reconfigure the application to use another port.

Frequently Asked Questions

How do I find the process using a port on Windows without command line?

Open Resource Monitor (type “resmon” in Start), go to the Network tab, and expand “Listening Ports”. You’ll see the port number, PID, and process name. For a more detailed, real-time view, download Sysinternals TCPView, which shows all connections and listening ports with the process name and lets you right-click to end the process.

What does “Address already in use” mean?

It means the port you’re trying to bind to is already occupied by another process. The OS prevents two programs from listening on the same port (unless they use SO_REUSEPORT, which is rare). You need to stop the existing process or choose a different port for your application.

Why does netstat show a process but I can’t kill it?

You might not have sufficient permissions. On Windows, run Command Prompt as Administrator. On Linux/macOS, use sudo kill PID. Also, some processes are system services or protected by the OS; killing them may cause instability. If the process is a kernel thread, it may not have a user-space name.

Can I see which process is listening on a remote port?

No, you can only see local processes on your machine. To see what’s listening on a remote server, you need to log into that server and run the same commands. On your local machine, you can check if a remote port is open using telnet host port or nc -vz host port, but that doesn’t reveal the process on the remote side.

Is it safe to kill the process occupying a port?

Only if you’re sure it’s not a critical system service. For example, killing a process on port 80 (HTTP) might stop your web server, which could be intentional. But killing a process on port 135 (Windows RPC) could break system functionality. Always check the process name and its purpose before terminating it. When in doubt, search for the process name online.

How do I find the port for a specific process?

On Windows, use netstat -ano | findstr PID to see all ports associated with that PID. On Linux/macOS, use lsof -p PID -i or ss -tulpn | grep PID. This is useful when you know the application but not the port it uses.