Skip to content
Back to Blog
Linux & Server10 min read

How to Kill Process Linux: Managing CPU & Memory Hogs on Your VPS

Learn how to identify resource-hungry processes with ps, top, and htop, then use kill signals to stop them cleanly and keep your Linux VPS responsive under load.

Written by Abdul AbrorTechnical Hosting Support Engineer
How to Kill Process Linux: Managing CPU & Memory Hogs on Your VPS
On this page

When your VPS slows to a crawl or becomes unresponsive, the culprit is often a single process consuming all available CPU or memory. Knowing how to identify and terminate resource-hungry processes is fundamental for anyone managing a Linux server. This guide walks you through the essential tools—ps, top, htop, and kill—so you can diagnose bottlenecks and restore responsiveness quickly.

Why Process Management Matters

Every running application on your server is a process. A web server, database, backup script, or even a runaway PHP worker all compete for CPU cycles and RAM. When one process monopolizes resources, legitimate traffic suffers: sites load slowly, SSH sessions hang, and automated tasks timeout.

Understanding how to inspect process states, interpret resource usage, and send termination signals gives you precise control over system stability. Unlike rebooting the entire server, terminating a specific process preserves uptime for everything else.

Listing Processes with ps

The ps command provides a snapshot of current processes. By itself, ps shows only processes attached to your current terminal. To see everything running system-wide, use:

ps aux

This displays all processes with detailed columns:

  • USER: the account running the process
  • PID: process ID, the unique number you'll reference when killing
  • %CPU: percentage of CPU time consumed
  • %MEM: percentage of physical memory used
  • VSZ: virtual memory size in kilobytes
  • RSS: resident set size (physical RAM) in kilobytes
  • STAT: process state (R for running, S for sleeping, Z for zombie)
  • START: when the process began
  • TIME: cumulative CPU time
  • COMMAND: the executable and arguments

To find processes sorted by memory usage:

ps aux --sort=-%mem | head -n 10

For CPU usage:

ps aux --sort=-%cpu | head -n 10

These one-liners quickly highlight the top offenders. If you see a PHP-FPM worker consuming gigabytes of RAM or a backup script pegged at 100% CPU, you've found your target.

Another useful pattern is filtering by process name:

ps aux | grep apache2

This shows all Apache processes, making it easy to spot which worker threads are active and how much memory each consumes.

Real-Time Monitoring with top

While ps gives a static snapshot, top refreshes continuously, showing live resource usage. Launch it by typing:

top

You'll see a header summarizing system load, CPU states, memory, and swap, followed by a dynamically updating list of processes sorted by CPU usage.

Reading the top Display

The summary lines at the top reveal system-wide health:

  • load average: three numbers showing 1-minute, 5-minute, and 15-minute load. A load higher than your CPU core count indicates saturation.
  • %Cpu(s): breakdown of CPU time—user space, system, idle, waiting on I/O.
  • MiB Mem: total, used, free, and buffered/cached memory.
  • MiB Swap: swap space usage. Heavy swap activity means you're out of physical RAM.

The process table below shows PID, user, priority, virtual and resident memory, CPU and memory percentages, and command.

Interactive Commands in top

While top is running, you can press keys to change the view:

  • M: sort by memory usage
  • P: sort by CPU usage (default)
  • k: kill a process—prompts for PID and signal
  • u: filter by username
  • q: quit

Pressing M immediately highlights which processes are eating RAM. If you see MySQL or Elasticsearch consuming most of your memory, you know where to investigate further—either by tuning configuration or terminating the process if it's stuck.

Enhanced Monitoring with htop

While top is universally available, htop offers a friendlier interface with color-coded bars, mouse support, and easier navigation. Install it if it's not already present:

# Debian/Ubuntu
sudo apt install htop

# CentOS/RHEL/AlmaLinux
sudo yum install htop

Run it with:

htop

What Makes htop Better

  • Visual CPU and memory bars: each core gets its own bar, making multi-core load distribution obvious.
  • Tree view: press F5 to see processes in a parent-child hierarchy, useful for tracking which daemon spawned a misbehaving worker.
  • Search and filter: press F3 to search by name, F4 to filter.
  • Point-and-click: you can click on a process and press F9 to send signals without typing PIDs.
  • Configuration: F2 opens settings where you can customize columns and colors.

htop makes it trivial to spot a PHP process fork bomb or a cron job stuck in an infinite loop. The color-coded CPU bars immediately show if one core is maxed while others sit idle, often a sign of single-threaded bottlenecks.

Terminating Processes with kill

Once you've identified the problem process and noted its PID, you terminate it using kill. Despite its name, kill actually sends signals—messages instructing the process to perform an action. The default signal is SIGTERM, which asks the process to shut down gracefully.

Common Signals

  • SIGTERM (15): polite termination request. The process can clean up, close files, and exit. Default if you don't specify a signal.
  • SIGKILL (9): immediate, forceful termination. The kernel stops the process without giving it a chance to clean up. Use as a last resort.
  • SIGHUP (1): hangup signal. Many daemons reload configuration when they receive SIGHUP instead of terminating.
  • SIGINT (2): interrupt, equivalent to pressing Ctrl+C.
  • SIGSTOP (19): pause the process without terminating.
  • SIGCONT (18): resume a stopped process.

Syntax

To send SIGTERM to a process:

kill PID

For example:

kill 1234

To send a specific signal, use -SIGNAL or -s SIGNAL:

kill -9 1234
kill -KILL 1234
kill -s SIGKILL 1234

All three forms send SIGKILL.

Graceful Shutdown First

Always try SIGTERM before SIGKILL. SIGTERM allows the process to flush buffers, release locks, and notify other processes. If you SIGKILL a database mid-transaction, you risk corruption. Wait a few seconds after SIGTERM, then escalate to SIGKILL only if the process refuses to die.

kill 1234
sleep 5
ps -p 1234 > /dev/null && kill -9 1234

This snippet sends SIGTERM, waits five seconds, checks if the process still exists, and only then sends SIGKILL.

Killing by Name with pkill and killall

Typing PIDs manually is tedious if you need to stop multiple processes. pkill and killall let you match by name.

pkill

pkill matches process names using patterns:

pkill php-fpm

This sends SIGTERM to every process whose name contains "php-fpm". To send a different signal:

pkill -9 php-fpm

You can filter by user:

pkill -u www-data php-fpm

This targets only PHP-FPM processes running as the www-data user.

killall

killall matches the exact command name:

killall php-fpm8.1

Be cautious: if you specify a broad name, you might terminate more than intended. Always double-check with ps or pgrep first:

pgrep -a php-fpm

This lists all matching processes before you kill them.

Handling Zombie Processes

Sometimes ps or top shows processes in state Z—zombie processes. A zombie is a process that has finished execution but whose parent hasn't read its exit status yet. Zombies consume no CPU or memory beyond a tiny kernel structure, but large numbers can exhaust the process table.

You cannot kill a zombie directly because it's already dead. The solution is to terminate or restart the parent process. Identify the parent with:

ps -ef | grep defunct

Look at the PPID column (parent PID). Send SIGTERM to the parent, which should then reap its zombie children. If the parent is PID 1 (init or systemd), the zombie will be cleaned up automatically once the parent exits or the system is rebooted.

Keeping Your VPS Responsive Under Load

Killing processes reactively solves immediate crises, but proactive monitoring prevents them. Here are strategies to maintain stability:

Set Resource Limits with ulimit

Prevent a single process from consuming all memory or spawning unlimited children:

ulimit -m 512000   # max memory (KB)
ulimit -u 100      # max user processes

You can set persistent limits in /etc/security/limits.conf.

Use systemd Resource Controls

For services managed by systemd, enforce memory and CPU limits in the service unit file:

[Service]
MemoryLimit=512M
CPUQuota=50%

Reload and restart the service:

sudo systemctl daemon-reload
sudo systemctl restart myservice

Monitor with cron and Alert Scripts

Schedule a script to check load and memory every few minutes and email you if thresholds are exceeded. Combine uptime, free, and ps in a shell script.

Tune Application Configurations

MySQL, Apache, Nginx, and PHP-FPM all have configuration knobs for max connections, worker processes, and memory limits. Right-sizing these prevents resource exhaustion.

Enable Swap (Carefully)

Swap provides breathing room when RAM fills, but heavy swapping destroys performance. Configure a modest swap file or partition—typically equal to RAM size—and set vm.swappiness low so the kernel prefers RAM.

Use Process Supervisors

Tools like supervisord or systemd restart crashed processes automatically, reducing downtime. They also log restarts, helping you identify recurring issues.

Practical Workflow Example

Suppose your VPS becomes sluggish. SSH is slow, and your website times out. Here's a step-by-step response:

  1. Check load: Run uptime or top. If the load average is 10 on a 2-core VPS, you're overloaded.
  2. Identify the hog: Press M in top or run ps aux --sort=-%mem | head. You see a PHP process using 80% memory.
  3. Get the PID: Note the process ID, say 5678.
  4. Attempt graceful stop: kill 5678 and wait 10 seconds.
  5. Verify: Run ps -p 5678. If it's gone, you're done. If not, escalate: kill -9 5678.
  6. Check impact: Refresh your site. Load drops, SSH is responsive, problem solved.
  7. Investigate root cause: Check logs (/var/log/php-fpm/, /var/log/apache2/) to see why that process went rogue—bad plugin, infinite loop, traffic spike.

This workflow isolates the issue, restores service, and leaves a trail for post-incident analysis.

Conclusion

Managing Linux processes is a core skill for maintaining a healthy VPS. The combination of ps for snapshots, top or htop for live monitoring, and kill for controlled termination gives you the tools to diagnose and resolve resource bottlenecks quickly. By understanding signals and practicing graceful shutdowns, you minimize risk while keeping your server responsive under load. Pair these techniques with proactive monitoring and resource limits, and you'll prevent most crises before they impact your users.

FAQ

What's the difference between kill -9 and kill -15?

SIGTERM (15) asks the process to terminate gracefully, allowing cleanup. SIGKILL (9) forces immediate termination with no cleanup. Use SIGTERM first; escalate to SIGKILL only if the process ignores SIGTERM.

Can I kill a process I don't own?

Only root can send signals to processes owned by other users. Regular users can only kill their own processes. Use sudo kill if you need to terminate another user's process.

Why does a process still appear after I kill it?

It may be a zombie (state Z) waiting for the parent to reap it, or it respawned via a supervisor or cron job. Check parent PID or service manager status.

How do I kill all processes for a user?

Use pkill -u username to send SIGTERM to all processes owned by that user. Add -9 to force kill: pkill -9 -u username.

What if SSH is too slow to login?

Use your hosting provider's console or VNC access. If those aren't available, reboot the server via the control panel. Once accessible, investigate what caused the overload.

Is it safe to kill system processes?

Killing essential system processes (init, systemd, sshd) can make the server unusable. Always verify what a process does before terminating it. Stick to user-space application processes unless you're certain.