How to Find and Kill a Process Using a Specific Port on macOS

In this tutorial, we will show you how to find and kill a process using a specific port on macOS.

macOS Kill Process on Port

If you have ever run software on your Mac and run into an error about a port being in use, you will want to know how to find the process using that port and then how to kill that process.

When you kill a process, you stop it from running on your system. Which, in this case, will free up the port for use by other programs.

Luckily, macOS makes finding out what process is using a port a straightforward process. In fact, we can find a process by specifying a port with a single simple-to-use command.

You might run into a port-in-use error when using software like Apache or NGINX since they use very commonly used ports.

Finding and Killing the Process Running on a Particular Port on macOS

The following section will show you a straightforward way to kill a process running on a specific port on macOS.

Before proceeding any further, you must open the terminal on your macOS device.

Using the Terminal to Find a Process using a Specific Port on your Mac

1. To kill a process using a specific port on your Mac, we must first find out its ID.

To get its process ID, you must open the terminal before continuing. You can press COMMAND + T to open the terminal quickly.

2. Once you have the terminal open, we can utilize the “lsof” command to find what process is running on the specified port.

This command is used to list open files, and by specifying the “-i” option, it will also list open network sockets. We need to specify the port on which we are looking for our running program.

Ensure you replace “” with the port you searching for programs.

sudo lsof -i tcp:

For example, if we wanted to kill the process on macOS using port 8080, we would use the following command to get the programs ID.

sudo lsof -i tcp:8080

3. If there is a process running on that specific report, macOS will return its process ID. This ID will be a random-looking number that we can use to kill the running process.

Below, you can see the information about the process using this port. The value you want is under the “PID” header.

Based on this information, we want to kill the process with ID 64395. There are multiple processes in our example since NGINX spawns multiple processes.

COMMAND   PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx   64395 emmet    6u  IPv4 0x62d815b5ad0e4fd3      0t0  TCP *:http-alt (LISTEN)
nginx   64396 emmet    6u  IPv4 0x62d815b5ad0e4fd3      0t0  TCP *:http-alt (LISTEN)

Killing a Process on macOS using a Specific Port

4. Once you have the program’s process ID using a port on macOS, killing it becomes very simple.

All you need to do is use the following command and replace “” with the process ID.

Using the “-15” option, we are attempting a soft termination of the program. If this doesn’t work, try replacing it with “-9“, which will force close the running program.

kill -15 

For example, to kill the process with the ID “64395“, we would use the following command.

kill -15 

5. You can verify there aren’t any more processes using the specific port on your Mac by using the “lsof” command again. However, this time, you should hopefully see nothing in its output.

sudo lsof -i tcp:

Simple One Liner to Find and Kill a Process on macOS Using a Port

6. Now, if you prefer not to have to remember a couple of commands, you can write down this very simple one-liner.

This command on macOS will find the process running on a specific port and kill it in one go. Ensure you replace “” with the port you are trying to kill a process for.

kill -15 $(lsof -ti:)

Conclusion

Hopefully, at this stage, you will now understand how to find and kill a process using a port on macOS.

This process is relatively straightforward but involves using the terminal. There are only two commands that you will need to remember.

The first is the “lsof” command. This command is what you use to find the ID of a process using a particular port on your Mac.

The other command is “kill“, which we use to stop a specific process from running on your system.

Please feel free to comment below if you need any assistance with working out how to find and kill processes on macOS.

If you found this tutorial to be helpful, we highly recommend checking out our other Mac tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Server Status

Aradippou Chat Larnaca Nicosia

Chat Links

Official Links.

Chat.

Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:

Archives

Follow me on Mastodon

Super Club Radio

Mighty Deals

CyIRC

CyIRC Tweets

Chat Icon