Killport: Stopping Processes by Port Number in Linux

Linux TLDR
Last Updated:
Reading time: 3 minutes

killport is a CLI tool that provides a simple solution to stop processes by their port number, thereby resolving the problem of users struggling to identify the processes behind an open port.

This way, you don’t have to follow the traditional method of finding the open port, then looking for the responsible processes behind that port, then finding the process PID, and then stopping it.

Instead, all you need to do is pass the port number to the killport command as an argument, and then it will immediately stop the processes behind that port by sending β€œSIGTERM” signals.

In this article, I’ll show you its features, how to install killport on Linux, how to list open ports, and then stop it by using the port number with killport.

Tutorial Details

DescriptionKillport: Killing Processes Listening on Specific Ports
Difficulty LevelLow
Root or Sudo PrivilegesYes
OS CompatibilityLinux, Windows, and macOS
Internet RequiredYes (for installation)

Features of Killport

The following is a list of standout features of Killport:

  • It’s cross-platform and available for Linux, Windows, and macOS.
  • Kill processes by port number.
  • You can kill multiple ports at once.
  • Specify a β€œSIGHUPβ€œ, β€œSIGKILLβ€œ, or β€œSIGTERM” signal that is to be sent.
  • Use the verbose option to receive detailed output.

How to Install Killport on Linux

There are multiple ways to install killport on your desired Linux distribution; the recommended one is by using the β€œbrew” command. So, if you have Homebrew installed on your Linux system, you can use the following command (it also works for macOS).

$ brew install killport

If you have the Cargo package manager installed on your Linux, Windows, or macOS, then you can easily install it using the following command:

$ cargo install killport

Finally, on Linux and macOS, if you prefer, you can use its installation script (not recommended) using the curl command. The script will automatically download the latest binary package and place it in the users β€œ/bin” directory.

Make sure that you include β€œ$HOME/.local/bin” in your $PATH environment variable. If you’re unsure how to do this, simply add this line: β€œexport PATH="$HOME/.local/bin:$PATH"” at the end of your shell configuration file (β€œ~/.bashrc” for bash).
$ curl -sL | sh

Once completed, you can run the following command to confirm its successful installation on your Linux system:

$ killport --help


killport help section

Usage of Killport

Once killport is installed, you can start killing processes based on their port number. To showcase its usage, I’ll first check the list of all open ports on my Linux system using the β€œss” or β€œnetstat” commands:

$ ss -tulpn


$ netstat -tulpn


listing open ports linux

In the above picture, ports β€œ80” and β€œ88” are shown to be in a LISTEN state, handled by Nginx and Apache2. To stop one or both of these open ports, you can use the following killport commands:

You can easily terminate a user-initiated process, but system-level processes require root or sudo privileges.
# The following command will kill port 80.
$ sudo killport 80

# The following command will kill ports 80 and 88 at onces.
$ sudo killport 80 88


killing services by port number using killport

Voila, you’ve successfully terminated the two processes responsible for listening on ports β€œ80” and β€œ88β€œ. To show you the proof, I’ll re-check the list of all open ports on my Linux system.

confirming the port is closed

If you notice, the two ports mentioned aren’t on the list. Now, you might be thinking that in the output there is an β€œ[ERROR] ESRCH: No such process” message, which makes it seem that there was never such a process and nothing has been terminated. Then,Β my friend, you are mistaken.

The message we are receiving in the output is the last signal sent to the process, ensuring that the target process is terminated. To confirm, you can enable the verbose mode using the β€œ-v” flag and see for yourself that this message appears at the end.

$ sudo killport -v 80 88


enabling verbose mode in killport

I’ve told you, look. Finally, to kill the process using the specific β€œSIGHUPβ€œ, β€œSIGKILLβ€œ, or β€œSIGTERM” signal, you can use the β€œ-s” flag. However, if you’re unsure of the differences between them, you can refer to the following table:

Signal NameSignal ValueBehavior
SIGHUP1Hangup (a less secure way)
SIGKILL9Kill Signal (forceful)
SIGTERM15Terminate (default and safest)

So, to kill the process responsible for ports β€œ80” and β€œ88” by sending a β€œSIGKILL” signal, use the following command:

$ sudo killport -v 80 88 -s sigkill


killing process using sigkill signal in killport

That’s it. Here comes the end of this article. To give you my opinion, I find this tool pretty amazing because finding the process PID and then killing it makes me sick. I’m usually aware of which ports are started by me and can easily identify them, so when they are not in need, I can quickly kill them using the β€œkillport” command.

Now, I am interested in knowing your thoughts and opinions on this, so do share them in the comment section.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.