How to stop the process of a certain port?

To stop a process that is running on a certain port, you need to know the process ID (also called PID). In Unix-like systems (like Linux, macOS), you can use the following steps:

  1. First, you need to find the process that is listening on that port. This can be done with the lsofor netstatcommand. For example, if you want to find out which process is listening on port 8080, you can use the following command:

    sudo lsof -i :8080
    

    or

    sudo netstat -tuln | grep :8080
    

    Both commands will list all processes listening on port 8080, including their PIDs.

  2. Once you find the PID, you can use killthe command to stop the process. For example, if the PID is 1234, then you can run:

    kill 1234
    

    If the process is unwilling to stop, you can send a stronger signal, such as SIGKILL (signal 9), to force the process to terminate:

    kill -9 1234
    

In Windows system, you can use "Resource Monitor" or "Task Manager" to see which process is using a certain port, and you can directly end this process.

Note that only a user with sufficient privileges can end a process, so you may need to use the command in Linux or macOS sudo, and administrator privileges in Windows.

おすすめ

転載: blog.csdn.net/m0_57236802/article/details/131306467