Mac users may sometimes encounter a situation where a process occupies a port, which causes other applications or processes to be unable to use the port. If you encounter this situation, for example, when trying to use React.js, you find that a program is already running on port 3000, you can easily track the process that occupies the port through the command line.
We will show how to find and terminate a port-occupying process on MacOS.
How to find a process that occupies a port on a Mac
The syntax used is as follows: Replace PORTNUMBER with the process number you want to find the occupied port:
sudo lsof -i :PORTNUMBER
For example, find a process that occupies port 445:
sudo lsof -i :445
Or find a process that occupies port 3000: sudo lsof -i :3000
How to find and terminate a process that occupies a port on a Mac
Once you have obtained the PID (process ID) from the output of the lsof command, you can choose to exit the application, close the service, or terminate the process to release and unlock the occupied port.
The easiest way to terminate a process is to use the kill command:
kill -9 PID
For example, if the process ID that occupies port 3000 is "8384", you can use the following command:
kill -9 8384
If the process belongs to root, admin, or other users, you need to prepend sudo:
sudo kill -9 8384
It is worth mentioning that the lsof command used here is applicable on Mac and can also be used in Linux systems.
We assume that you have a certain understanding of the command line, and of course if not, you may not be here, and you will not be worried about which process occupies a specific port.
There are other ways to do this, but obviously we use the lsof command here, which is a very powerful tool, which can also be used to find processes that listen to TCP ports, find applications or processes that interact with specific files, find all processes that use internet connections, etc.
Are there any other ways to determine which process occupies a specific port? Please share your own solution in the comments below.
The above is the detailed content of How to Find Process Locking a Port on Mac. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you're using a Mac with multiple monitors, you might be curious about how to display the Dock on all screens or whether it's possible to add a Dock to secondary displays.The good news is that you can configure the Dock to appear on any screen conn

Fortnite is once again available for iPhone and iPad users, bringing joy to many gamers. However, there's still no official version for Mac (at least not yet). Despite that, Apple Silicon Mac owners aren’t completely out of luck—you can run the iOS/i

If you've owned multiple Apple devices over the years, you might find yourself in a situation where some of those older Macs, iPhones, iPads, or other Apple hardware have been sold, given away, or traded. No matter how they left your possession, it's

iCloud Private Relay is an excellent privacy feature included with the iCloud subscription, designed to safeguard your online activity and browsing by masking your IP address (using a temporary one) and encrypting DNS lookups. This prevents third pa

Are you using Screen Time to manage your or your child’s Mac usage? If yes, you likely already know that it allows you to set app limits, schedule downtime on the Mac, and more. Additionally, you can also choose specific apps that remain accessible a

macOS Sequoia is a solid operating system that brings some impressive features like iPhone Mirroring, and while performance is excellent for many users, not everyone experiences the same level of speed. If you're finding macOS Sequoia slower than pre

If you frequently use iMessage, then you've likely shared numerous web links in your chats — maybe an article, a video, a tweet, a song, or anything else. Locating these links later can be quite frustrating, but thankfully there's a simpler method th

Advanced Mac users familiar with the command line can swiftly set up a MacOS Tahoe 26 beta virtual machine by entering a few commands into Terminal, using tart. Tart is a command-line utility for managing virtual machines and offers one of the quicke
