How to close the specified port on Mac

The command is very simple, but I can't remember it every time, so I have to check it. . .

The background is that I want to repackage during the running of the project, because the previous process has not ended, resulting in the original port being occupied, and the packaging prompts me to open a new port, but I just want the original port (mainly because I don’t want to change the configuration, Hahaha).

Two steps to get it done:

1. Query the process information of the specified port number

lsof -i:端口号

For example, the port number information I need to query here is 3000, and the operation command is executed, and the result is as shown in the figure:

2. End the process

// 这里的PID是第一步的时候查出来的,注意看上图框起来的部分
kill -9 PID

The PID I execute here is 27857, because my node needs to be repackaged, mainly to find the corresponding PID.

 Well, it's that quick and easy! ! !

Guess you like

Origin blog.csdn.net/weixin_38629529/article/details/125566722