How to Find the Process That is Using a Port
When developing multiple applications or trying out demos, it is common to have multiple programs running on different ports on your computer. However, it can be challenging to remember which application is running on a specific port. In this blog post, we will discuss how to determine which program is listening on a port using the lsof
command.
To find the program that is listening on a specific port, you can use the following command:
1 | lsof -i :<port number> |
For example, to find the program listening on port 1313, you can run:
1 | lsof -i :1313 |
This command will display the following output, providing information about the command, PID, user, file descriptor, device, size/offset, node, and name associated with the port:
1 | COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME |
In this example, the program hugo
with PID 8698 is listening on port 1313.
If you want to terminate the program that is using the port, you can use the kill
command followed by the PID. For instance, to terminate the program with PID 8698, you can run:
1 | kill 8698 |
By following these steps, you can easily identify the process that is using a specific port and terminate it if needed. Keep in mind that you should exercise caution when terminating processes, as it may impact other running applications.
Tags: port, process, lsof, command, terminate