How to check the port usage and end the process on Mac

Title: How to Check Port Occupancy and End Process on Mac

insert image description here

On a Mac, if you want to see which processes are currently using a particular port on your system and need to kill a process to free up the port, here are some ways to help you do that.

Step 1: Open the Terminal application

Find the terminal application in Launchpad or the application folder, and double-click to open it.

Step 2: Check the port usage

Enter the following command in the terminal to view all port occupancy in the current system:

sudo lsof -i :<端口号>

Replace <port number> with the port number you want to query. For example, if you want to check the usage of port 80, the command should be:

sudo lsof -i :80

After pressing the Enter key, the system will list all process information that is using the port, including process name, process ID, etc.

Step 3: End the process

If you are sure you want to kill a process to free up the port, you can use the following command:

sudo kill -9 <进程ID>

Replace <process ID> with the actual ID of the process you want to kill; add -9 to force kill the process. For example, if you want to kill process ID 12345, the command would be:

sudo kill -9 12345

Make sure you really want to end the process, as this action is irreversible.

Step 4: Enter the administrator password

After entering the above end process command in the terminal, you will be asked to enter the administrator password. When entering the password, no characters will be displayed in the terminal, but you can type normally. After entering the password, press the Enter key.

Step 5: Verify that the process is over

After ending the process, you can run the command from step 2 again to verify that the process has ended.

Through the above steps, you can check the occupation of a specific port on your Mac, and end the related process to release the port. Note, use caution when using the sudo command, make sure you know what you are doing, and only end processes you know about.

Guess you like

Origin blog.csdn.net/weixin_45626288/article/details/130828106