To stop a process running on a specific port in Linux, you can follow one of the following methods:
Method 1: Using the lsof command
1. Open a terminal window.
2. Run the following command to identify the process ID (PID) of the process running on the specific port:
lsof -i :<port_number>
Replace <port_number>
with the actual port number on which the process is running. For example, to find the process running on port 8080:
lsof -i :8080
The output will display the process details along with the PID.
3. Once you have identified the PID, you can use the kill command to stop the process. Run the following command:
kill <PID>
Replace <PID>
with the actual process ID. For example, to stop the process with PID 12345:
kill 12345
This will send a termination signal to the process running on the specific port, causing it to stop.
Related Article: How to SCP to a Folder in Linux: Copy Folder RemoteLocal
Method 2: Using the fuser command
1. Open a terminal window.
2. Run the following command to identify the process ID (PID) of the process running on the specific port:
fuser -n tcp <port_number>
Replace <port_number>
with the actual port number on which the process is running. For example, to find the process running on port 8080:
fuser -n tcp 8080
The output will display the PID of the process.
3. Once you have identified the PID, you can use the kill command to stop the process. Run the following command:
kill <PID>
Replace <PID>
with the actual process ID. For example, to stop the process with PID 12345:
kill 12345
This will send a termination signal to the process running on the specific port, causing it to stop.
Additional Notes:
– If the process does not stop after sending the termination signal, you can use the kill -9
command to forcefully kill the process. However, this should only be used as a last resort, as it does not allow the process to perform any cleanup operations.
– It is important to ensure that you have the necessary permissions to stop a process. If you are not running the commands as a privileged user, you may need to use sudo
before the commands to run them with elevated privileges.
– If you are unable to identify the process running on a specific port using the above methods, it is possible that the process is running as a system service or daemon. In such cases, you can use the service management commands specific to your Linux distribution to stop the service. For example, on Ubuntu, you can use the systemctl
command to stop a service:
sudo systemctl stop <service_name>
Replace <service_name>
with the name of the service you want to stop.
– It is generally a good practice to gracefully stop a process by sending the termination signal before resorting to forceful termination (kill -9
). This allows the process to perform any necessary cleanup operations and exit gracefully.
Related Article: How To Find Files Based On Wildcard In Linux