Kill Process Running on a Specific Port in Linux (2024)

Killing a process in Linux usually involves using the process ID with the kill command. You can also use the process name with killall command.

This works when you know the process ID or name. But in some cases, you may not know it or you just don't necessarily need to know it.

For example, if you want to kill the processes running on specific ports, you may not need to know the process ID or name at all. You can terminate a process based on the port number it is using.

Let me show you how to do that.

Terminating processes based on their port numbers

The fuser command combined with the -k (kill) option will end all associated processes that are listening on a TCP or UDP port. Simply provide the port number and type (TCP or UDP) in the fuser command.

For instance, to end a process on UDP port 81, use the fuser command as:

sudo fuser -k 81/udp
Kill Process Running on a Specific Port in Linux (1)

Similarly, use the fuser command to terminate a process on TCP port 3306:

sudo fuser -k 3306/tcp

You can use the lsof command to verify that processes are no longer running on the target port.

The classic way of killing processes using certain ports

For those who would rather not use fuser, lsof may be used to determine which processes are using a certain port and then use this information with the kill command.

As an instance, to kill all the process running on TCP port 3306, use the below command to detect the process id:

sudo lsof -i TCP:3306

And now kill it with its pid:

kill -9 <pid_value>

One thing to note here is that certain processes like mysqld and apache2 might restart after you have killed them using the above commands. Even if you use the killall command, they will still appear after some time.

In such cases, I advise you to use application specific commands to stop a service. For example, to kill the Apache process on Ubuntu, use the command:

sudo systemctl stop apache2
Kill Process Running on a Specific Port in Linux (2)

This will completely kill the particular process.

Wrapping Up

This article covered how to terminate a process running on a specific port. With the fuser command, you don't need to know the process details. Otherwise, the classic method of getting the process ID associated with port first and then killing it works as well.

Kill Process Running on a Specific Port in Linux (2024)

FAQs

How do I stop a process on a specific port in Linux? ›

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> ...
  3. Once you have identified the PID, you can use the kill command to stop the process. Run the following command:
Oct 16, 2023

How do you kill whatever is running on port 8080? ›

Now that you've identified the process using port 8080, you can terminate it using the sudo kill -9 command. This command sends a SIGKILL signal to the specified process, forcing it to terminate immediately.

How do I close port 4444? ›

From the Windows Task Manager, select the Processes Tab. Select the PID Matching with command result (in this case, the PID of the process is 1480) corresponding to port 4444 processes. Right-click on the process. Select End Process.

How do I terminate a process on a specific port? ›

The fuser command combined with the -k (kill) option will end all associated processes that are listening on a TCP or UDP port. Simply provide the port number and type (TCP or UDP) in the fuser command. You can use the lsof command to verify that processes are no longer running on the target port.

How do I stop a process running on port? ›

Summary
  1. Find what Process ID (PID) is occupying your port with netstat -a -o -n.
  2. (Optional) Confirm this PID is for the expected program with tasklist.
  3. Terminate the process with taskkill /f /pid #### (replace #### with your PID)

How do I stop a port 3000 server from running? ›

You can use the npx kill-port 3000 command to kill a port already in use. This package is designed to kill all processes running on a port number, making it convenient to handle port conflicts without manually searching for the process ID.

How do I stop port 80 from running? ›

Start the Windows Task Manager by pressing Ctrl-Alt-Del. Click on the Processes tab and select the application/process that is using port 80. Note that you can add a PID column by selecting View>Select Columns... and choosing PID from the list. Click the End Process button.

How to check which process is running on port? ›

In order to check which application is listening on a port, you can use the following command from the command line:
  1. For Microsoft Windows: netstat -ano | find "1234" | find "LISTEN" tasklist /fi "PID eq 1234"
  2. For Linux: netstat -anpe | grep "1234" | grep "LISTEN"
May 19, 2022

How do I close port 8443? ›

Access to the https://ip_address:8443/config on the network interface is enabled by default. To disable remote configuration access, from the /config interface | Remote Access | and select "Disabled" on the Remote Configuration Access drop down list and click the "Save Changes" button.

How do I close port 53? ›

You will need to create a firewall traffic rule to block any traffic using port 53. Remember that there's both UDP and TCP traffic that can use port 53, and to block either or both as appropriate. Also note that while blocking DNS traffic except to specific resolvers is a good idea, it does not stop DNS tunneling.

What happens if I close port 445? ›

Note that blocking TCP 445 will prevent file and printer sharing, including over apps – if this is required for business, you may need to leave the port open on some internal firewalls or use encryption keys.

What is kill 9 in Linux? ›

The kill -9 command sends a SIGKILL signal to a service, shutting it down immediately. An unresponsive program ignores a kill command, but it shuts down whenever a kill -9 command is issued. Use this command with caution since it bypasses the standard shutdown routine, and any unsaved data will be lost.

How do you kill a specific process in Unix? ›

top
  1. Press 'k' key when top command is running.
  2. It will ask you to enter the Process Id which you want to terminate.
  3. Type the Process Id.
  4. Then it will ask you the signal you want to use for killing the Process.
  5. Type '9' which is a SIGKILL. By default the signal will be SIGTERM ('15'). ...
  6. press enter.
Jan 6, 2021

What is kill 2 in Linux? ›

Kill -2 sends an interrupt (2 is the value associated with SIGINT). This will wake up the sleep call but then the loop continues. If you send a 15 (SIGTERM), the process should terminate.

How to stop a process on port 8080 Linux? ›

This fuser 8080/tcp will print you PID of process bound on that port. And this fuser -k 8080/tcp will kill that process. Works on Linux only. More universal is use of lsof -i4 (or 6 for IPv6).

How to stop port 3000 in Linux? ›

To kill a port from the terminal, you can use the lsof command to find the process id and then the kill command to terminate that process. If you prefer a one-liner, the npx kill-port 3000 command can kill all processes running on port 3000.

How to stop a process on a port in Ubuntu? ›

How to kill ports in Ubuntu
  1. lsof -ti :$PORT. Now kill the process ID that you obtain by running above command.
  2. kill $(lsof -ti :$PORT) ...
  3. kill -9 $(lsof -ti :$PORT) ...
  4. sudo kill -9 $(lsof -ti :$PORT) ...
  5. netstat -ano | findstr $PORT. ...
  6. taskkill /F /pid $PID.
Nov 9, 2022

Top Articles
Latest Posts
Article information

Author: Jerrold Considine

Last Updated:

Views: 5664

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Jerrold Considine

Birthday: 1993-11-03

Address: Suite 447 3463 Marybelle Circles, New Marlin, AL 20765

Phone: +5816749283868

Job: Sales Executive

Hobby: Air sports, Sand art, Electronics, LARPing, Baseball, Book restoration, Puzzles

Introduction: My name is Jerrold Considine, I am a combative, cheerful, encouraging, happy, enthusiastic, funny, kind person who loves writing and wants to share my knowledge and understanding with you.