On this page
- How do I read memory with free?
- How do I list processes with ps?
- How do I use top and htop?
- How do I stop a runaway process?
- How do I find which process uses a file or port?
- What is the OOM killer and how do I spot it?
- How do I protect important services from the OOM killer?
- How do I check load and find a slow server?
- Questions
How do I read memory with free?
Use free -h and trust the available column, not free. Linux fills unused RAM with file cache because empty memory is wasted; that cache is handed back the moment an application needs it:
free -h
grep -E "MemTotal|MemAvailable|SwapTotal|SwapFree" /proc/meminfo
vmstat 1 5A small free value with a healthy available value is normal. Pressure starts when available drops near zero and swap usage climbs. In vmstat, steady non-zero values in the si and so columns mean the system is actively swapping, which slows everything down. A modest swap file gives a cushion, but it is not a substitute for enough RAM.
How do I list processes with ps?
ps takes a snapshot, which makes it ideal for scripts and quick sorting:
ps aux --sort=-%mem | head -10
ps aux --sort=-%cpu | head -10
ps -eo pid,user,%cpu,%mem,rss,etime,cmd --sort=-rss | head
ps -fu deploy
pstree -p | lessRSS is the resident memory in kilobytes, the RAM a process really occupies; VSZ includes mapped but unused address space and is rarely useful. etime shows how long each process has run, which helps spot a service that restarts again and again. pgrep -a node finds processes by name with their full command line.
How do I use top and htop?
top is installed everywhere and refreshes every few seconds. Inside it, press M to sort by memory, P for CPU, 1 to show each vCPU, c for full command lines, k to send a signal and q to quit.
Watch the st value in the CPU line. It shows steal time, the share of time your virtual CPU waited for the host. Our plans use shared vCPUs, so a small amount is expected; if it stays high while your own load is low, open a ticket with the numbers. The wa value is time spent waiting for disk.
htop adds colour, mouse support and a tree view. It is in the standard repositories on Ubuntu and Debian and in EPEL on Rocky and Alma:
# Ubuntu and Debian
sudo apt install htop
# Rocky Linux and AlmaLinux
sudo dnf install epel-release && sudo dnf install htop
htopIn htop, F5 toggles the tree, F6 picks the sort column, F9 sends a signal and F4 filters by name. The btop and htop guide covers more live monitors.
How do I stop a runaway process?
Ask politely first with SIGTERM, then force with SIGKILL only if it ignores you:
kill 4321
sleep 5; ps -p 4321
sudo kill -9 4321
pkill -f "python3 worker.py"SIGTERM lets the program flush buffers and close files; SIGKILL cannot be caught and may leave half-written data. For anything managed by systemd, use sudo systemctl stop name instead, or systemd will simply start it again. To lower the priority of a busy job rather than stop it, use renice +10 -p 4321, and ionice -c3 -p 4321 for disk-heavy work.
How do I find which process uses a file or port?
lsof lists open files, and on Linux network sockets count as files too:
sudo lsof -i :443
sudo lsof -i -P -n | grep LISTEN
sudo lsof /var/log/syslog
sudo lsof -p 4321 | head
sudo lsof +D /mnt/dataThe same port question is often faster with sudo ss -tlnp, which needs no extra package. If lsof is missing, install it with sudo apt install lsof or sudo dnf install lsof. A common use is finding why a disk cannot be unmounted or why space did not come back after deleting a file; sudo lsof +L1 lists deleted files still open.
What is the OOM killer and how do I spot it?
When RAM and swap run out, the kernel out-of-memory killer ends the process it scores as the best victim, usually the largest one. Applications disappear without an error of their own, so look in the kernel log:
journalctl -k | grep -iE "out of memory|oom-kill|killed process"
sudo dmesg -T | grep -i oom
systemctl list-units --state=failedA line such as Out of memory: Killed process 2210 (java) names the victim and its memory use at that moment. If a database or Bitcoin node keeps getting killed, the real fix is to lower its cache settings, add swap as a buffer, or move to a plan with more RAM via move to a larger plan.
How do I protect important services from the OOM killer?
Shift the risk with systemd settings so a less important process dies first, and cap memory hogs so they only hurt themselves:
sudo systemctl edit postgresql[Service]
OOMScoreAdjust=-500Values range from -1000 (never kill) to 1000 (kill first). For a worker that sometimes leaks, a hard cap is better:
[Service]
MemoryMax=768M
MemoryHigh=640MWith MemoryHigh the kernel reclaims memory from the service early, and MemoryMax kills only that service when the cap is reached. Watch per-service usage live with systemd-cgtop, and read systemd services for the rest of the unit file.
How do I check load and find a slow server?
Start with the load average, then split the problem into CPU, memory or disk:
uptime
nproc
vmstat 2 5
cat /proc/pressure/memory
cat /proc/pressure/ioA load average around the number of vCPUs from nproc means the server is fully busy; well above it means work is queuing. High wa or io pressure points to disk, high si/so to memory, high us or sy to CPU. Pressure stall files show the percentage of time tasks waited for each resource, a clearer signal than load alone. For history rather than a snapshot, install a monitor such as Netdata.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Inspect processes and memory
Why does Linux show almost no free memory?
Unused RAM is used as file cache and released on demand. Look at available in free -h; that is what applications can still get.
What is a zombie process?
A process that has exited but whose parent has not collected its status yet. It uses no memory or CPU. Many zombies point to a bug in the parent; restarting the parent clears them.
Is high steal time a problem?
Some steal time is normal on shared vCPUs. If it stays high for long periods while your own load is light, open a support ticket with the top output.
How much memory does a process really use?
RSS is a good everyday measure. Shared libraries are counted in each process, so adding up RSS overstates the total. smem or /proc/PID/smaps_rollup give a more exact figure.
Should I disable the OOM killer?
No. Without it, an out-of-memory server freezes instead of recovering. Use OOMScoreAdjust and MemoryMax to steer it.
More in Server basics
- Create a sudo user
- Add a swap file
- Change the hostname
- Time zone and time sync
- File and directory permissions
- Choose a Linux distribution
- Upgrade Ubuntu to the next LTS
- Upgrade Debian to a new major release
- Rocky or AlmaLinux to a new major version
- Automatic security updates
- Run an app as a systemd service
- Schedule jobs with cron and systemd timers
- Environment variables on Linux
- Check disk space and find what fills it
- Read the hardware and system report
- Reboot and shut down safely
- Customise the login message (MOTD)
- Remote desktop with Xfce and xrdp
- SELinux on Rocky Linux and AlmaLinux
- Keep sessions alive with tmux
- SFTP-only users in a chroot
- apt and dnf package management
- First-hour checklist for a new server
- Upgrade FreeBSD to a new release