How to Find and Stop Processes Using Too Many Resources

A single runaway process can consume all available CPU or memory and bring your entire VPS to a crawl. This guide covers identifying the culprit and safely stopping it.

Finding the Top CPU Consumers

top

Press Shift+P inside top to sort by CPU (usually the default). Or non-interactively:

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

Finding the Top Memory Consumers

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

Using htop for a Clearer View

sudo apt install htop -y
htop

Press F6 to change the sort column, F9 to kill a selected process.

Investigating a Specific Process

ps -p PID -o pid,ppid,cmd,%cpu,%mem

Find open files held by a process:

sudo lsof -p PID

Stopping a Process Gracefully

Always try a graceful termination first:

kill PID

This sends SIGTERM, allowing the process to clean up and exit on its own.

Force-Killing an Unresponsive Process

Only if graceful termination fails after a few seconds:

kill -9 PID

SIGKILL terminates immediately without allowing cleanup — use as a last resort, since it can leave temp files or locks behind.

Killing by Process Name

pkill -f process_name

Identifying Zombie Processes

ps aux | grep 'Z'

Zombie processes are already dead but not yet reaped by their parent; they usually clear on their own, but a persistent buildup indicates a bug in the parent process.

Finding What's Using a Specific Port

sudo ss -tulpn | grep :PORT

Preventing Runaway Processes: Resource Limits

For services managed by systemd, you can cap resource usage directly in the unit file:

[Service]
MemoryMax=512M
CPUQuota=50%
sudo systemctl daemon-reload
sudo systemctl restart myapp

Common Errors

"Operation not permitted" when killing a process — the process belongs to another user; use sudo kill PID.

Process restarts immediately after being killed — it's likely managed by systemd with Restart=always; stop it properly with systemctl stop instead.

Best Practices

  • Always attempt kill (SIGTERM) before kill -9
  • Investigate why a process is consuming excess resources rather than just repeatedly killing it
  • Set resource limits on services prone to memory leaks

FAQ

What's the difference between kill and kill -9?
kill asks the process to terminate gracefully; kill -9 forces immediate termination without cleanup, and should only be used when graceful termination fails.

Related Articles

  • How to Check VPS Resource Usage (CPU, RAM & Disk)
  • How to Manage Services with systemd and systemctl
  • How to Enable and Configure Swap on a Linux VPS
  • kill process, top, htop, cpu usage, linux troubleshooting
  • 0 Uživatelům pomohlo
Byla tato odpověď nápomocná?

Související články

How to Update and Upgrade Your Ubuntu or Debian VPS

Keeping your VPS updated is one of the most important and simplest maintenance tasks — it...

How to Enable and Configure Swap on a Linux VPS (Ubuntu & Debian)

Swap is disk space Linux can use as overflow memory when physical RAM is exhausted. It won't make...

How to Manage Services with systemd and systemctl

systemd is the service manager used by Ubuntu, Debian, and most modern Linux distributions to...

How to Read and Analyze Linux Logs with journalctl

On modern Ubuntu and Debian systems, journalctl is the central tool for viewing system and...

How to Schedule Tasks with Cron on a Linux VPS

Cron is the standard Linux job scheduler, used to automate recurring tasks like backups, log...