Prerequisites
Before killing a process, make sure you have:
- SSH access to your VPS
- Root or sudo privileges
- The Process ID (PID) of the frozen application
⚠️ Warning: Killing system processes can crash your server. Only kill processes you recognize as problematic.
Step 1: Identify the Frozen Process
First, find the Process ID (PID):
topOr:
ps aux | grep "process-name"Example - find a frozen Apache process:
ps aux | grep apache2The second column is the PID (e.g., 12345).
Method 1: Using kill (Gentle Termination)
Send SIGTERM signal (default) - allows process to clean up:
kill PIDExample:
kill 12345With explicit SIGTERM:
kill -15 PIDMethod 2: Using kill -9 (Force Kill)
If gentle kill doesn't work, force kill immediately:
kill -9 PIDExample:
kill -9 12345⚠️ kill -9 does not allow any cleanup. Use only as last resort.
Method 3: Using pkill (Kill by Name)
Kill all processes with a specific name:
pkill process-nameExample:
pkill nginxForce kill by name:
pkill -9 nginxMethod 4: Using killall (Kill by Exact Name)
killall process-nameExample:
killall apache2Method 5: Kill from top/htop Interactive
In top:
- Press k
- Enter the PID
- Enter signal (15 for gentle, 9 for force)
In htop:
- Select process with arrow keys
- Press F9
- Select SIGTERM (15) or SIGKILL (9)
- Press Enter
Understanding Kill Signals
Most common signals:
- SIGHUP (1) - Reload configuration
- SIGINT (2) - Interrupt (like Ctrl+C)
- SIGTERM (15) - Terminate gracefully (default)
- SIGKILL (9) - Force kill immediately
- SIGSTOP (19) - Pause process
- SIGCONT (18) - Resume paused process
Kill All Frozen Processes of a User
pkill -u usernameForce kill all user processes:
pkill -9 -u usernameKill All Processes Except Specific Ones
Kill all except your SSH session (advanced):
kill -9 -1⚠️ The above command will kill ALL processes including your SSH session!
Check if Process is Still Running After Kill
ps aux | grep PIDOr:
kill -0 PIDReturns success if process exists.
Common Scenarios
Apache/Nginx is frozen:
systemctl restart nginxInstead of killing individually.
MySQL not responding:
systemctl restart mysqlUser program frozen (like Python script):
pkill -f "python script.py"Automatically Kill High-Memory Processes (Monitor Script)
#!/bin/bash
MAX_MEM=80 # 80% memory usage
MEM_USED=$(free | grep Mem | awk '{print ($3/$2) * 100}')
if (( $(echo "$MEM_USED > $MAX_MEM" | bc -l) )); then
ps aux --sort=-%mem | head -5 | awk '{print $2}' | xargs kill -9
fi✅ You can now terminate frozen or problematic processes on your Hostxpeed VPS.