{"id":5627,"date":"2026-01-09T10:33:54","date_gmt":"2026-01-09T10:33:54","guid":{"rendered":"https:\/\/commandlinux.com\/?p=5627"},"modified":"2026-01-09T10:37:50","modified_gmt":"2026-01-09T10:37:50","slug":"kill-process-on-port","status":"publish","type":"post","link":"https:\/\/commandlinux.com\/qa\/kill-process-on-port\/","title":{"rendered":"How to Kill Process On Port\u00a0"},"content":{"rendered":"\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    <link rel=\"preconnect\" href=\"https:\/\/fonts.googleapis.com\">\n    <link rel=\"preconnect\" href=\"https:\/\/fonts.gstatic.com\" crossorigin>\n    <link href=\"https:\/\/fonts.googleapis.com\/css2?family=IBM+Plex+Sans:wght@400;500;600&#038;family=IBM+Plex+Mono:wght@400;500&#038;display=swap\" rel=\"stylesheet\">\n    <style>\n\n.kill-process-on-port-container        h2 {\n            font-size: 28px;\n            font-weight: 600;\n            margin: 2.5em 0 1em 0;\n            color: #1a202c;\n            letter-spacing: -0.02em;\n        }\n\n.kill-process-on-port-container         h3 {\n            font-size: 21px;\n            font-weight: 600;\n            margin: 2em 0 0.8em 0;\n            color: #2d3748;\n        }\n\n.kill-process-on-port-container         code {\n            font-family: 'IBM Plex Mono', 'Courier New', monospace;\n            background: #f7fafc;\n            padding: 2px 6px;\n            border-radius: 3px;\n            font-size: 14px;\n            color: #1a202c;\n        }\n\n.kill-process-on-port-container         pre {\n            background: #f7fafc;\n            border-left: 3px solid #4299e1;\n            padding: 16px;\n            margin: 1.2em 0;\n            overflow-x: auto;\n            border-radius: 4px;\n        }\n\n.kill-process-on-port-container         pre code {\n            background: none;\n            padding: 0;\n            font-size: 14px;\n            line-height: 1.6;\n        }\n\n.kill-process-on-port-container         ul {\n            margin: 1em 0 1.5em 1.5em;\n            list-style-type: disc;\n        }\n\n.kill-process-on-port-container         ul li {\n            margin-bottom: 0.6em;\n            line-height: 1.6;\n        }\n\n        table {\n            width: 100%;\n            border-collapse: collapse;\n            margin: 1.5em 0;\n            font-size: 15px;\n        }\n\n        table th {\n            background: #edf2f7;\n            padding: 12px;\n            text-align: left;\n            font-weight: 600;\n            border-bottom: 2px solid #cbd5e0;\n        }\n\n        table td {\n            padding: 12px;\n            border-bottom: 1px solid #e2e8f0;\n        }\n\n        table tr:last-child td {\n            border-bottom: none;\n        }\n\n .note {\n            background: #ebf8ff;\n            border-left: 4px solid #4299e1;\n            padding: 16px 20px;\n            margin: 1.5em 0;\n            border-radius: 4px;\n        }\n\n.note strong {\n            color: #2c5282;\n            font-weight: 600;\n        }\n\n.warning {\n            background: #fff5f5;\n            border-left: 4px solid #f56565;\n            padding: 16px 20px;\n            margin: 1.5em 0;\n            border-radius: 4px;\n        }\n\n.warning strong {\n            color: #c53030;\n            font-weight: 600;\n        }\n\n.tip {\n            background: #f0fff4;\n            border-left: 4px solid #48bb78;\n            padding: 16px 20px;\n            margin: 1.5em 0;\n            border-radius: 4px;\n        }\n\n.tip strong {\n            color: #2f855a;\n            font-weight: 600;\n        }\n\n        .faq-section {\n            margin-top: 3em;\n        }\n\n        .faq-item {\n            margin-bottom: 1em;\n            border: 1px solid #e2e8f0;\n            border-radius: 6px;\n            overflow: hidden;\n        }\n\n        .faq-item input[type=\"checkbox\"] {\n            display: none;\n        }\n\n        .faq-item label {\n            display: block;\n            padding: 18px 20px;\n            cursor: pointer;\n            background: #f7fafc;\n            transition: background 0.2s;\n            position: relative;\n        }\n\n        .faq-item label:hover {\n            background: #edf2f7;\n        }\n\n        .faq-item label::after {\n            content: '+';\n            position: absolute;\n            right: 20px;\n            top: 50%;\n            transform: translateY(-50%);\n            font-size: 24px;\n            font-weight: 300;\n            color: #4299e1;\n            transition: transform 0.3s;\n        }\n\n        .faq-item input[type=\"checkbox\"]:checked + label::after {\n            transform: translateY(-50%) rotate(45deg);\n        }\n\n        .faq-item label h3 {\n            margin: 0;\n            font-size: 18px;\n            font-weight: 500;\n            color: #2d3748;\n            padding-right: 30px;\n        }\n\n        .faq-answer {\n            max-height: 0;\n            overflow: hidden;\n            transition: max-height 0.3s ease;\n            background: #ffffff;\n        }\n\n        .faq-item input[type=\"checkbox\"]:checked ~ .faq-answer {\n            max-height: 500px;\n        }\n\n        .faq-answer p {\n            padding: 0 20px 20px 20px;\n            margin: 0;\n            color: #4a5568;\n            line-height: 1.6;\n        }\n\n        a {\n            color: #4299e1;\n            text-decoration: none;\n            transition: color 0.2s;\n        }\n\n        a:hover {\n            color: #2b6cb0;\n            text-decoration: underline;\n        }\n    <\/style>\n<\/head>\n<body>\n\n<p>Have you encountered the &#8220;Address already in use&#8221; error when starting a service? This occurs when another process occupies the required port. Freeing up the port is crucial for smooth system operation, especially with Apache, Nginx, MySQL, PostgreSQL, and Docker. This guide shows how to kill process on port using commands like <code>lsof<\/code>, <code>ss<\/code>, <code>netstat<\/code>, and <code>fuser<\/code>.<\/p>\n\n<h2>Common Scenarios Where Port Conflicts Occur<\/h2>\n\n<ul>\n    <li>Starting a web server (Apache, Nginx, or Node.js) and finding the port already in use<\/li>\n    <li>Launching a database (MySQL, PostgreSQL, or MongoDB) and encountering a binding error<\/li>\n    <li>Deploying a containerized application where a process still runs on the host machine<\/li>\n<\/ul>\n\n<h2>Identify the Process ID Using the Port Number<\/h2>\n\n<p>Before you can kill process on port, identify the Process ID (PID). The PID is a unique number assigned to each running program. Identifying this number prevents accidental termination of unrelated processes.<\/p>\n\n<h3>Using lsof (List Open Files Command)<\/h3>\n\n<p>The <code>lsof<\/code> command lists open files and network connections. Run this command to find which process occupies a specific port:<\/p>\n\n<pre><code>lsof -i :PORT_NUMBER<\/code><\/pre>\n\n<p>Replace <code>PORT_NUMBER<\/code> with your actual port (example: 8080).<\/p>\n\n<p>The output displays:<\/p>\n\n<table>\n    <tr>\n        <th>Column<\/th>\n        <th>Description<\/th>\n    <\/tr>\n    <tr>\n        <td>COMMAND<\/td>\n        <td>Program name<\/td>\n    <\/tr>\n    <tr>\n        <td>PID<\/td>\n        <td>Process identifier needed for termination<\/td>\n    <\/tr>\n    <tr>\n        <td>USER<\/td>\n        <td>Account running the program<\/td>\n    <\/tr>\n    <tr>\n        <td>TYPE<\/td>\n        <td>Connection protocol (IPv4 or IPv6)<\/td>\n    <\/tr>\n<\/table>\n\n<div class=\"note\">\n    <strong>Note:<\/strong> Install <code>lsof<\/code> using your package manager if not already present. On Ubuntu\/Debian: <code>sudo apt install lsof<\/code>\n<\/div>\n\n<h3>Using ss (Socket Statistics Command)<\/h3>\n\n<p>The <code>ss<\/code> command is a modern replacement for <code>netstat<\/code>. It provides faster execution and more detailed output. Run this command:<\/p>\n\n<pre><code>ss -tulnp | grep PORT_NUMBER<\/code><\/pre>\n\n<p>This shows the process listening on your specified port with PID and process name.<\/p>\n\n<h3>Using netstat (Older Method)<\/h3>\n\n<p>While deprecated in some distributions, <code>netstat<\/code> remains useful:<\/p>\n\n<pre><code>netstat -tulnp | grep PORT_NUMBER<\/code><\/pre>\n\n<p>The final column displays the PID you need.<\/p>\n\n<h2>Methods to Kill Process on Port Using Its PID<\/h2>\n\n<p>Once you identify the PID, terminate it using one of these commands.<\/p>\n\n<h3>Using kill (Graceful Termination)<\/h3>\n\n<p>The <code>kill<\/code> command terminates processes in Linux. By default, it sends <code>SIGTERM<\/code> (signal 15), allowing the process to save data before exiting:<\/p>\n\n<pre><code>kill PID<\/code><\/pre>\n\n<p>This method allows proper shutdown and cleanup.<\/p>\n\n<div class=\"warning\">\n    <strong>Warning:<\/strong> Always try graceful termination first before using forceful methods. This prevents data loss and corruption.\n<\/div>\n\n<h3>Using fuser to Kill Process on Port<\/h3>\n\n<p>The <code>fuser<\/code> command directly finds and terminates processes on a specific port:<\/p>\n\n<pre><code>fuser -k -n tcp PORT_NUMBER<\/code><\/pre>\n\n<p>The <code>-k<\/code> flag kills the process, and <code>-n tcp<\/code> specifies the TCP protocol. Use <code>-n udp<\/code> for UDP ports. This one-liner eliminates manual PID searching.<\/p>\n\n<h3>Using lsof to Kill Process on Port<\/h3>\n\n<p>Combine <code>lsof<\/code> with <code>kill<\/code> for instant termination:<\/p>\n\n<pre><code>kill -9 $(lsof -t -i :PORT_NUMBER)<\/code><\/pre>\n\n<p>This command extracts the PID and sends <code>SIGKILL<\/code> for immediate termination.<\/p>\n\n<div class=\"tip\">\n    <strong>Tip:<\/strong> Use <code>kill -9<\/code> only when standard termination fails. The forceful signal prevents cleanup operations.\n<\/div>\n\n<h2>Verify That the Port is Free<\/h2>\n\n<p>After termination, confirm the port is available. Run the identification command again:<\/p>\n\n<pre><code>lsof -i :PORT_NUMBER<\/code><\/pre>\n\n<p>Empty output confirms successful termination. The port now accepts new connections.<\/p>\n\n<h2>Troubleshooting Common Issues<\/h2>\n\n<h3>Permission Denied<\/h3>\n\n<p>System processes require elevated privileges. Add <code>sudo<\/code> before commands on Linux:<\/p>\n\n<pre><code>sudo kill -9 PID<\/code><\/pre>\n\n<p>On Windows, run Command Prompt as Administrator.<\/p>\n\n<h3>Process Keeps Restarting<\/h3>\n\n<p>Some services restart through system managers. Stop these using service commands:<\/p>\n\n<pre><code>sudo systemctl stop SERVICE_NAME<\/code><\/pre>\n\n<p>Examples:<\/p>\n\n<ul>\n    <li>Apache: <code>sudo systemctl stop apache2<\/code><\/li>\n    <li>Nginx: <code>sudo systemctl stop nginx<\/code><\/li>\n    <li>MySQL: <code>sudo systemctl stop mysql<\/code><\/li>\n<\/ul>\n\n<h3>Process Not Found<\/h3>\n\n<p>If the process is not listed, it may have already exited. Another application might have replaced it. Run the identification command again to check current port usage.<\/p>\n\n<h2>Conclusion<\/h2>\n\n<p>Knowing how to kill process on port is essential for managing server applications and troubleshooting conflicts. Whether you use <code>lsof<\/code>, <code>ss<\/code>, <code>fuser<\/code>, or <code>netstat<\/code>, these commands help you quickly identify and terminate unwanted processes. Master these techniques to maintain smooth system operations and resolve port conflicts efficiently.<\/p>\n\n<div class=\"faq-section\">\n    <h2>FAQs<\/h2>\n    \n    <div class=\"faq-item\">\n        <input type=\"checkbox\" id=\"faq1\">\n        <label for=\"faq1\"><h3>How do I kill process on port 8080 in Linux?<\/h3><\/label>\n        <div class=\"faq-answer\">\n            <p>Run <code>lsof -i :8080<\/code> to find the PID, then execute <code>kill -9 PID<\/code>. Alternatively, use <code>fuser -k -n tcp 8080<\/code> for a one-line solution.<\/p>\n        <\/div>\n    <\/div>\n    \n    <div class=\"faq-item\">\n        <input type=\"checkbox\" id=\"faq2\">\n        <label for=\"faq2\"><h3>What command kills all processes using a specific port?<\/h3><\/label>\n        <div class=\"faq-answer\">\n            <p>Use <code>fuser -k -n tcp PORT_NUMBER<\/code> to kill all processes on the specified port instantly without manual PID identification.<\/p>\n        <\/div>\n    <\/div>\n    \n    <div class=\"faq-item\">\n        <input type=\"checkbox\" id=\"faq3\">\n        <label for=\"faq3\"><h3>How do I check if a port is free after killing the process?<\/h3><\/label>\n        <div class=\"faq-answer\">\n            <p>Run <code>lsof -i :PORT_NUMBER<\/code> or <code>ss -tulnp | grep PORT_NUMBER<\/code>. Empty output confirms the port is now available for new connections.<\/p>\n        <\/div>\n    <\/div>\n    \n    <div class=\"faq-item\">\n        <input type=\"checkbox\" id=\"faq4\">\n        <label for=\"faq4\"><h3>Why do I get permission denied when trying to kill process on port?<\/h3><\/label>\n        <div class=\"faq-answer\">\n            <p>System processes require elevated privileges. Prefix your command with <code>sudo<\/code> (example: <code>sudo kill -9 PID<\/code>) to gain necessary permissions for termination.<\/p>\n        <\/div>\n    <\/div>\n    \n    <div class=\"faq-item\">\n        <input type=\"checkbox\" id=\"faq5\">\n        <label for=\"faq5\"><h3>What is the difference between kill and kill -9?<\/h3><\/label>\n        <div class=\"faq-answer\">\n            <p><code>kill<\/code> sends SIGTERM for graceful termination, allowing cleanup. <code>kill -9<\/code> sends SIGKILL for immediate termination without cleanup. Use graceful termination first.<\/p>\n        <\/div>\n    <\/div>\n<\/div>\n\n<\/body>\n<\/html>\n\n\n","protected":false},"excerpt":{"rendered":"<p>Have you encountered the &#8220;Address already in use&#8221; error when starting a service? This occurs when another process occupies the required port. Freeing up the port is crucial for smooth system operation, especially with Apache, Nginx, MySQL, PostgreSQL, and Docker. This guide shows how to kill process on port using commands like lsof, ss, netstat,<\/p>\n","protected":false},"author":1,"featured_media":5628,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-5627","post","type-post","status-publish","format-standard","has-post-thumbnail","category-qa"],"_links":{"self":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/5627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/comments?post=5627"}],"version-history":[{"count":6,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/5627\/revisions"}],"predecessor-version":[{"id":5634,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/posts\/5627\/revisions\/5634"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media\/5628"}],"wp:attachment":[{"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/media?parent=5627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/categories?post=5627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commandlinux.com\/wp-json\/wp\/v2\/tags?post=5627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}