A comprehensive cross-platform port management utility that automatically identifies and terminates processes using specific ports. When automatic termination fails, it provides detailed manual instructions for different operating systems.
- Cross-platform support: Windows, Linux, and macOS
- Multiple detection methods: Socket binding, psutil library, and system commands
- Automatic process termination: Graceful and forceful termination attempts
- Detailed process information: PID, name, command line, and connection details
- Manual instructions: System-specific guidance when automatic termination fails
- Environment-based configuration: Customizable timeouts and behavior via .env file
- Verbose and quiet modes: Configurable output levels
git clone <repository-url>
cd kill_port
pip install -r requirements.txtpython setup.py installThis will install the tool with console commands:
port-manager <port>kill-port <port>
- Required: Python 3.6+ with standard library
- Recommended:
psutillibrary for enhanced process management - Configuration:
python-dotenvfor environment variable loading
The program includes fallback functionality for systems without psutil.
# Direct execution
python port_manager.py 8080
python port_manager.py --port 3306
python port_manager.py -p 80
# After installation
port-manager 8080
kill-port 3306# Direct execution
python port_manager_gui.py
python run_gui.py
# After installation
port-manager-gui
kill-port-guiThe GUI provides:
- Real-time port monitoring with auto-refresh
- Interactive process list with detailed information
- One-click process termination with confirmation dialogs
- Live operation logging and status updates
- Manual instruction display for failed terminations
- Environment-driven configuration
- Cross-platform native interface
python port_manager.py <port> # Basic usage
python port_manager.py -p <port> # Alternative port specification
python port_manager.py --port <port> # Long form port specification
python port_manager.py -v <port> # Verbose mode
python port_manager.py -q <port> # Quiet mode# Check and kill processes on port 8080
python port_manager.py 8080
# Verbose output for debugging
python port_manager.py -v 3306
# Quiet mode for scripting
python port_manager.py -q 80The tool uses environment variables for configuration. Create a .env file in the project directory:
# All timeouts are in seconds
PROCESS_TIMEOUT=10
SOCKET_TIMEOUT=1
FORCE_KILL_TIMEOUT=5
GRACEFUL_KILL_TIMEOUT=3
VERBOSE_OUTPUT=true
DEBUG=falsePROCESS_TIMEOUT: Timeout for subprocess operations (default: 10)SOCKET_TIMEOUT: Timeout for socket operations (default: 1)FORCE_KILL_TIMEOUT: Timeout for force kill operations (default: 5)GRACEFUL_KILL_TIMEOUT: Timeout for graceful termination (default: 3)VERBOSE_OUTPUT: Enable verbose output (default: true)DEBUG: Enable debug mode for detailed error information (default: false)
GUI_WINDOW_SIZE: Initial window size (default: 900x700)GUI_AUTO_REFRESH_INTERVAL: Auto-refresh interval in seconds (default: 5)GUI_MAX_LOG_LINES: Maximum log lines to keep (default: 1000)GUI_DEFAULT_PORT: Default port to load on startupGUI_AUTO_MONITOR: Enable auto-monitoring on startup (default: false)GUI_THEME: GUI theme - default or dark (default: default)GUI_CONFIRM_KILLS: Confirm before killing processes (default: true)GUI_SHOW_SYSTEM_PROCESSES: Show system processes in GUI (default: true)
-
Port Detection: Uses multiple methods to detect if a port is in use:
- Socket connection attempts
- Socket binding attempts
- psutil network connections (if available)
- System commands (netstat)
-
Process Identification: Discovers processes using the port via:
- psutil process information (recommended)
- System-specific commands (lsof, netstat, tasklist)
-
Process Termination: Attempts termination using:
- psutil graceful and force termination
- System kill commands (SIGTERM, SIGKILL on Unix; taskkill on Windows)
-
Manual Instructions: Provides detailed, system-specific instructions when automatic termination fails
- Windows: Uses
netstat,tasklist,taskkill, andwmic - Linux: Uses
netstat,lsof,kill, and/procfilesystem - macOS: Uses
netstat,lsof,kill, and BSD-specific utilities
This is a defensive security tool designed for legitimate system administration:
- Provides detailed process information before termination
- Attempts graceful termination before forceful killing
- Requires appropriate system privileges for process termination
- Includes comprehensive manual instructions for security-conscious environments
- No network communication or external dependencies beyond system tools
The tool includes comprehensive error handling for:
- Invalid port numbers (1-65535 range validation)
- Permission errors (insufficient privileges)
- Process access denied scenarios
- System command failures
- Network operation timeouts
Port Manager - Checking port 8080
==================================================
⚠ Port 8080 is currently in use
Found 1 process(es) using port 8080:
1. PID: 12345
Name: node.exe
Status: LISTEN
Local Address: 127.0.0.1:8080
Attempting to terminate 1 process(es)...
✓ Successfully terminated process 12345 (node.exe)
✓ SUCCESS: Port 8080 is now available
Successfully terminated 1 process(es).
Port Manager - Checking port 443
==================================================
⚠ Port 443 is currently in use
Found 1 process(es) using port 443:
1. PID: 4
Name: System
Status: LISTEN
Local Address: 0.0.0.0:443
Attempting to terminate 1 process(es)...
✗ Failed to terminate process 4 (System)
⚠ Port 443 is still in use after termination attempts
============================================================
MANUAL PROCESS TERMINATION REQUIRED
============================================================
[Detailed manual instructions follow...]
- Permission Denied: Run with elevated privileges (sudo/Administrator)
- Process Not Found: Process may have terminated between detection and kill attempt
- System Process: Some system processes cannot be terminated and require service management
- Port Still in Use: Check for parent processes that may respawn the terminated process
Enable debug mode for detailed error information:
# Set in .env file
DEBUG=true
# Or set environment variable
export DEBUG=true # Linux/macOS
set DEBUG=true # WindowsMIT License - See LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues, questions, or contributions, please use the project's issue tracker.