macOS: How to Kill Processes on Port


In some instances, we find ourselves in need of forcing a particular program or a process to terminate working. Often, this happens whenever the program stops responding or hangs suddenly. On Mac OS, the application can use one or multiple processes to function.

There are straightforward methods to force a program to stop, for example, the “Force Quit” command, which you can activate by pressing [⌘⌥ esc] in the Apple Menu. You’ll then see all the apps you can force quit, but this option does not show any processes. 

Although this method is straightforward, sometimes you may not want to end a particular application but a problematic process. You can do this by accessing the OSX Terminal.

You can do this by following a few steps, which are listed below.

  1. Open the OSX Terminal app, and go to the running processes list.
  2. Search for the process you want to terminate.
  3. Terminate the process.

Through this guide, we’ll go in more in-depth about killing processes on Mac OS. But before, let’s learn a few things about the Terminal.

What is the OSX Terminal?

The OSX Terminal is similar to what the Command Prompt is for PC users. As a terminal emulator, the application provides text-based access to the operating system, in contrast to the mostly graphical nature of the user experience of macOS.

Not only can you kill processes, but you also conduct a series of different tasks that will make using your laptop a lot easier. You may view directories, modify files and see detailed data about the active processes, as we explained above.

How to use OSX Terminal

As with everything else, the first step you should take is to open the Terminal tool. You can do this by going to the Utility folder or by typing “Terminal” in Spotlight. You will see a particular icon that resembles the following characters: >_.

Once the tool starts running, you’ll see how a window opens and starts showing text. The first sentence should tell you the exact date of your last log-in. The second line allows you to enter and execute commands; it is known as the “command prompt.” You will notice that this zone has your device’s name besides your account name. 

When you first open the Terminal tool, it will always be opened at the Home Folder.

How to access the processes from the Terminal

The next step is to type ps -ax, and you’ll see the list with all the active processes in your device. There will be other details, such as the PID and the running time, for instance. Other information includes the process name and its location.

However, it can be a bit overwhelming to find a specific process as there may be too many for you to count. But you don’t have to worry – you can see what each process is about as they are identified in the CMD column correctly. You may also identify them using their PID.

You can also find a particular process by using the grep command. You can use it together with the ps -ax command. Like:

ps –ax |grep (app name)

You will then get a result showing all the information about that particular process.

How to terminate processes using the Terminal

Before terminating that particular process, please make sure it is the correct path. Otherwise, it may lead to unwanted consequences. Still, we recommend being familiar with the process ID as it makes everything straightforward.

That being said, there are three main ways of killing a process by using the Terminal.

  • You can use the PID. You must enter kill followed by the PID (for instance, kill 12347), and the process will be terminated immediately.
  • Additionally, you can be more drastic and kill all the process that contains the app’s name at once. For this method, you’ll use the killall command followed by the application’s name. 

How to kill process on port

You can also kill the process on port. For this method, you’ll need to use the Terminal, and in the command prompt, you must enter the following command: lsof -i: port #

Once you’ve found the specific port number, please type the following command to kill the process: kill $(lsof -t -i:”Port #”)

Sometimes, what we describe above may not work for some apps with higher privileges. If that’s your case, please add a “-9” before the dollar sign, like this: kill -9 $(lsof -t -i:”Port #”).

Previous ArticleNext Article