search
HomeSystem TutorialLINUXHow To Kill A Process Running On A Specific Port In Linux

How To Kill A Process Running On A Specific Port In Linux

This guide details how to identify and terminate Linux processes bound to specific network ports. This is crucial for troubleshooting unresponsive applications or freeing ports for other services. We'll explore several command-line tools to accomplish this task efficiently.

Introduction

Multiple processes can concurrently utilize network ports. An unresponsive process can disrupt application functionality or service availability, necessitating termination to release the occupied port. For example, an unresponsive Apache web server (typically using port 80 or 443) requires termination and restarting to restore website accessibility. This tutorial covers using fuser, lsof, netstat, and ss commands to locate and terminate these processes.

Identifying and Terminating Processes with fuser

The fuser command identifies processes using specific files or sockets. It's part of the psmisc package; install it if needed using your distribution's package manager (e.g., sudo apt install psmisc on Debian/Ubuntu, sudo pacman -S psmisc on Arch Linux).

  1. Identify the process: Use fuser <port_number>/tcp</port_number> (or /udp for UDP). For instance, fuser 8080/tcp shows processes using TCP port 8080.

  2. Terminate the process: fuser -k 8080/tcp terminates processes using TCP port 8080. Note that ports may remain in a TIME_WAIT state briefly after termination.

Using lsof to Identify and Kill Processes

lsof (list open files) provides detailed information about open files and associated processes.

  1. Find the process ID (PID): sudo lsof -i :<port_number></port_number> lists processes using the specified port. For example, sudo lsof -i :8080 shows processes using port 8080. Locate the PID.

  2. Terminate the process: Use sudo kill -9 <pid></pid>, replacing <pid></pid> with the process ID. -9 sends a forceful SIGKILL signal.

One-liner lsof Command for Termination:

A concise one-liner combines process identification and termination: kill -9 $(lsof -t -i:8080 -sTCP:LISTEN). This kills processes listening on TCP port 8080. Use cautiously; SIGKILL is forceful.

netstat and ss for Service Termination

netstat and ss (socket statistics) display network connection details. ss is generally preferred for its efficiency and clearer output.

  1. Identify the service: Use sudo netstat -tnlp | grep <service_name></service_name> or sudo ss -tnlp | grep <service_name></service_name> to find the PID of the service (e.g., grep apache).

  2. Terminate the service: Use sudo kill <pid></pid> or sudo kill -9 <pid></pid> to terminate the process.

Frequently Asked Questions (FAQ)

(This section remains largely unchanged from the original, as it provides valuable information.)

Conclusion

fuser, lsof, netstat, and ss offer robust methods for managing processes and ports. Choose the tool best suited for your needs and always exercise caution when forcefully terminating processes. Remember the potential for brief port unavailability due to the TIME_WAIT state.

The above is the detailed content of How To Kill A Process Running On A Specific Port In Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Create GUI Applications In Linux Using PyGObjectHow to Create GUI Applications In Linux Using PyGObjectMay 13, 2025 am 11:09 AM

Creating graphical user interface (GUI) applications is a fantastic way to bring your ideas to life and make your programs more user-friendly. PyGObject is a Python library that allows developers to create GUI applications on Linux desktops using the

How to Install LAMP Stack with PhpMyAdmin in Arch LinuxHow to Install LAMP Stack with PhpMyAdmin in Arch LinuxMay 13, 2025 am 11:01 AM

Arch Linux provides a flexible cutting-edge system environment and is a powerfully suited solution for developing web applications on small non-critical systems because is a completely open source and provides the latest up-to-date releases on kernel

How to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxHow to Install LEMP (Nginx, PHP, MariaDB) on Arch LinuxMay 13, 2025 am 10:43 AM

Due to its Rolling Release model which embraces cutting-edge software Arch Linux was not designed and developed to run as a server to provide reliable network services because it requires extra time for maintenance, constant upgrades, and sensible fi

12 Must-Have Linux Console [Terminal] File Managers12 Must-Have Linux Console [Terminal] File ManagersMay 13, 2025 am 10:14 AM

Linux console file managers can be very helpful in day-to-day tasks, when managing files on a local machine, or when connected to a remote one. The visual console representation of the directory helps us quickly perform file/folder operations and sav

qBittorrent: A Powerful Open-Source BitTorrent ClientqBittorrent: A Powerful Open-Source BitTorrent ClientMay 13, 2025 am 10:12 AM

qBittorrent is a popular open-source BitTorrent client that allows users to download and share files over the internet. The latest version, qBittorrent 5.0, was released recently and comes packed with new features and improvements. This article will

Setup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxSetup Nginx Virtual Hosts, phpMyAdmin, and SSL on Arch LinuxMay 13, 2025 am 10:03 AM

The previous Arch Linux LEMP article just covered basic stuff, from installing network services (Nginx, PHP, MySQL, and PhpMyAdmin) and configuring minimal security required for MySQL server and PhpMyadmin. This topic is strictly related to the forme

Zenity: Building GTK  Dialogs in Shell ScriptsZenity: Building GTK Dialogs in Shell ScriptsMay 13, 2025 am 09:38 AM

Zenity is a tool that allows you to create graphical dialog boxes in Linux using the command line. It uses GTK , a toolkit for creating graphical user interfaces (GUIs), making it easy to add visual elements to your scripts. Zenity can be extremely u

Top 22 Best Music Players for LinuxTop 22 Best Music Players for LinuxMay 13, 2025 am 09:25 AM

Some may describe it as their passion, while others may consider it a stress reliever or a part of their daily life. In every form, listening to music has become an inseparable part of our lives. Music plays different roles in our lives. Sometimes it

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor