Killing a Process Running on a Particular Port
In Linux, you can kill a process that is using a specific port by identifying the process ID (PID) associated with that port.
lsof command (short for "list open files") is used to list information about files and processes currently opened by the system.
Step 1: Identify the Process on the Port
Open your terminal and run the following command to find the process running on a particular port (replace
<PORT_NUMBER> with the port number you want to check):
lsof -i :<PORT_NUMBER>
The command will display information about the process, including the PID.
Step 2: Kill the Process
Once you have identified the PID associated with the port, you can use the
kill command to terminate the process. Use the following command to kill the process (replace
<PID> with the actual process ID):
Alternatively, you can use the
kill command with the
-9 option to forcefully terminate the process:
kill -9 <PID>
Example: Killing a Process on Port 8080
Let's say you want to kill the process running on port 8080. First, find the process ID associated with that port:
lsof -i :8080
Assuming the PID is 12345, you can then terminate the process using the
kill -9 12345