How to Find Process Locking a Port on Mac
Mac users may occasionally come across a situation where a process is locking a port, preventing another app or process from using that port. If you come across such a situation, for example maybe you’re trying to use React.js and find out that something is already running on port 3000, you can easily track down what process(es) are using a port on the Mac by turning to the command line.
We’ll show you how to find and kill what process is locking a port on MacOS.
How to Find What Process is Locking a Port on Mac
The syntax to use would be the following, replacing PORTNUMBER with the port number you wish to discover the process(es) using:
sudo lsof -i :PORTNUMBER
For example, to find the process using port 445:
sudo lsof -i :445
Or to find the process using and locking port 3000:
sudo lsof -i :3000
How to Find & Kill Process Locking a Port on Mac
Once you have the PID (process ID) from the command output of lsof, you can then either quit the app, shutdown the service, or terminate that process, to release and free up the locked port.
The simplest way to kill a process is with the kill command:
kill -9 PID
So for example, if the process ID using port 3000 is “8384” then you’d use the following command syntax:
kill -9 8384
If the process is owned by root, admin, or another user, you’d need to prefix the command with sudo:
sudo kill -9 8384
For what it’s worth, the lsof command used here is focused on the Mac, but will work the same in linux as well.
We’re assuming you have some knowledge of the command line, but of course if you did not then you likely wouldn’t be here in the first place, or worried about what is using or locking a port.
There are other ways to do this, but obviously here we are using the lsof command, which is very powerful, and can also use it to find what is listening on a TCP port, to find what apps or processes are interacting with particular files, to find all processes using internet connectivity, and more.
Do you have another method for determining what process is locking or using a particular port? Share with us your own approaches to this in the comments below.