Processes, Packages, Disk, Memory and Monitoring in Linux

DevOps and Cloud Engineering: Complete Course from Beginner to Advanced · Linux Fundamentals · 10 min read · Updated

Where to look first

  1. A server is slow or failing. Start with a short checklist instead of guessing.
  2. Check the processor and processes with top or htop. Is one program using it all?
  3. Check memory with free -m, and look at the available column.
  4. Check disk space with df -h. A full disk causes many odd failures.

When a server is slow or a site is down, the first questions are always the same. What is running? Is the disk full? Is memory used up? Is something using all the processor? This lesson teaches the commands that answer those questions, and then puts them together into a short script you can reuse. You will also learn how to install and update software with the package manager, which is how almost everything gets onto a Linux server.

Why do we need it?

When a server is slow or down, you need to find out quickly whether the processor, memory, disk or a single program is the cause. Package managers are how software gets onto the machine, so you must install and update safely.

A real-life example

A computer is like a kitchen at lunch time. The processor is the number of cooks, memory is the counter space, disk is the pantry and each process is an order being cooked. If the counter is full or the pantry is empty or one order hogs all the cooks, everything slows down. Your commands are the way you walk around the kitchen and see which one it is.

Processes

A process is a running program. Every process has a number called a PID. Linux starts a first process when it boots, and every other process is started by another one, so they form a family tree. These are the commands to know.

  • ps aux lists all processes with their owner, CPU use, memory use and command.
  • ps aux | grep node finds the processes whose line contains the word node.
  • top shows a live list sorted by CPU use. Press q to quit. Many people install htop, which is easier to read.
  • kill 1234 asks process 1234 to stop politely (it sends the TERM signal). kill -9 1234 forces it to stop. Use the force version only if the polite one fails, because the program gets no chance to save its work.
  • command & runs a command in the background, jobs lists them, and Ctrl+C stops the one in front.

Packages

A package manager downloads, installs, updates and removes software, and takes care of the other packages that software needs. Which one you use depends on the distribution.

# Debian and Ubuntu
sudo apt update              # refresh the list of available packages
sudo apt install nginx       # install
sudo apt upgrade             # update everything installed
sudo apt remove nginx        # remove it

# Red Hat family (Amazon Linux, Rocky, Alma, newer CentOS and RHEL)
sudo dnf install nginx
sudo dnf update
# older systems used: sudo yum install nginx

Always run apt update before apt install on Debian and Ubuntu, so the list is fresh. Only install software from the official repositories or from a vendor you trust, and read the instructions before adding a new repository or running a script from the internet.

Disk

  • df -h shows how full each disk is, in readable sizes. Look at the Use% column.
  • du -sh folder shows how big a folder is. du -sh * | sort -h lists the items in the current folder from small to large, which finds the space hogs quickly.
  • lsblk lists disks and partitions.
  • mount and /etc/fstab control where disks are attached. Edit fstab with great care: a wrong line can stop the machine from booting.

A full disk is one of the most common causes of strange failures: databases stop, logs cannot be written and uploads fail. Many teams set an alert at about 80 percent. That figure is a habit, not a rule. Choose what suits your system.

Memory

free -m shows memory in megabytes. Do not be alarmed if the free number is small. Linux uses spare memory to cache files, which makes things faster, and gives it back when programs need it. The column called available is the better number to watch. If the machine starts using swap (disk used as slow memory) heavily, it will feel very slow.

A small system report script

Here is a script that prints the host, uptime, memory and disk use, and exits with an error when the disk is fuller than a limit that you give. An exit code other than zero is how scripts tell other tools, such as a scheduler or a pipeline, that something is wrong. The script in this lesson was run on Linux in the course lab (bash 5, Python 3.13). The output shown is real. Your numbers (memory, disk, dates) will be different.

#!/usr/bin/env bash
# sysinfo.sh - a small health report. Usage: ./sysinfo.sh [disk_warn_percent]
set -euo pipefail
WARN="${1:-80}"

echo "Host:    $(hostname)"
echo "Kernel:  $(uname -sr)"
echo "Uptime:  $(uptime -p 2>/dev/null || uptime)"
echo

echo "Memory (MB):"
free -m | awk 'NR==1 || /^Mem:/'
echo

echo "Disk usage of / :"
USED=$(df -P / | awk 'NR==2 {gsub("%","",$5); print $5}')
echo "  ${USED}% used"
if [ "$USED" -ge "$WARN" ]; then
  echo "  WARNING: more than ${WARN}% full"
  exit 1
fi
echo "  OK (below ${WARN}%)"
$ ./sysinfo.sh 80
Host:    vm
Kernel:  Linux 6.18.44-fc-v378
Uptime:  up 4 minutes

Memory (MB):
               total        used        free      shared  buff/cache   available
Mem:            8022         483        7546          16         211        7539

Disk usage of / :
  34% used
  OK (below 80%)
exit code: 0
$ ./sysinfo.sh 1
Host:    vm
Kernel:  Linux 6.18.44-fc-v378
Uptime:  up 4 minutes

Memory (MB):
               total        used        free      shared  buff/cache   available
Mem:            8022         484        7545          16         211        7538

Disk usage of / :
  34% used
  WARNING: more than 1% full
exit code: 1

System monitoring in one minute

  • uptime shows how long the machine has been up and the load averages for the last 1, 5 and 15 minutes. A load near the number of CPU cores means the machine is busy.
  • top or htop for processes, free -m for memory, df -h for disk.
  • journalctl -xe and the files in /var/log for messages about what went wrong. You will use them in the next lesson.

Linux troubleshooting checklist

  1. What changed? A new deployment, a package update, a full disk?
  2. Is the machine up and reachable? Try SSH and uptime.
  3. Is a resource full? Check df -h, free -m and top.
  4. Is the service running? systemctl status name and journalctl -u name.
  5. Can it be reached? Check the port with the health script and the firewall.
  6. Read the log lines just before the first error, not only the last one.

Change one thing at a time and write down what you tried. Most problems are found by this simple order, not by clever guessing.

Architecture diagram

Here is the idea as a simple picture. You can use the same diagram in your own notes.

flowchart TD
  S[Server is slow] --> D{Disk full?}
  D -->|yes| D1[Find big files with du, clean up]
  D -->|no| M{Memory low?}
  M -->|yes| M1[Find the heavy process with top]
  M -->|no| C{CPU busy?}
  C -->|yes| C1[Identify the process, restart or fix]
  C -->|no| N[Check network and logs]

How to check it worked

  • You can find the process ID of a program and stop it.
  • You can install and remove a package on your system.
  • You can explain what the available column of free -m tells you.

How companies use it

DevOps engineers use these commands daily on servers and inside containers. Monitoring tools automate the same checks and send alerts. Teams script routine checks, like the system report in this lesson, and run them from cron or a pipeline.

Common errors and how to fix them

  • Disk is 100 percent full. Find big folders with du -sh * | sort -h, rotate or delete old logs, and add monitoring.
  • Could not get lock on /var/lib/dpkg. Another package command is running. Wait for it. Do not delete lock files unless you are sure nothing is running.
  • Unable to locate package. Run sudo apt update first, or check the package name.
  • Process will not stop. Try kill PID, wait, then kill -9 PID as a last resort.
  • Out of memory kills. Look at dmesg and the journal for OOM messages and find the process that grew.

Best practices

  • Run apt update before apt install.
  • Install only from trusted repositories.
  • Check disk and memory before and after big changes.
  • Alert before disks are completely full.
  • Keep scripts safe to run twice.

Interview questions with simple answers

  1. What is a process? A running program with a process ID (PID).
  2. How do you list processes? ps aux or top.
  3. What is the difference between kill and kill -9? kill asks politely. kill -9 forces the process to stop.
  4. How do you check disk usage? df -h for disks and du -sh for folders.
  5. What does the available column in free mean? Memory that can be used by programs without swapping.
  6. What is swap? Disk space used as slow extra memory.
  7. apt vs dnf? Package tools for Debian/Ubuntu and for the Red Hat family.
  8. What is load average? The average number of processes waiting for CPU over 1, 5 and 15 minutes.
  9. A server is slow. Where do you start? Check CPU, memory and disk, then logs and recent changes.
  10. Why do scripts return exit codes? So other tools know if the script succeeded.

Practical exercises

Try each one yourself before you look at the hint. Struggling for a few minutes is how the skill sticks.

  1. Find which process uses the most memory. Hint: ps aux --sort=-%mem | head.
  2. Install and remove a small package such as tree. Hint: apt install and apt remove.
  3. Fill a temporary file with data and watch df -h change, then delete it. Hint: fallocate -l 100M.
  4. Run the system report script with different limits and read the exit code. Hint: echo $?.
  5. Start a sleep 300 in the background, find its PID and stop it. Hint: &, ps, kill.

Mini project: Health report on a schedule

Take the system report script, add a line that prints the top three memory users, and run it from cron every hour, writing to a log file. Check the log after two hours and describe what you see.

Knowledge test

Answer the ten questions in the quiz at the end of this lesson. You pass with 60 percent. If an answer is wrong, read the explanation, then reread the part of the lesson it points to.

Frequently asked questions

What is the difference between apt and apt-get?

apt-get is the older tool and apt is the newer, friendlier front end for the same package system. Both work on Debian and Ubuntu. Use apt in a terminal and apt-get in scripts if you like stable behaviour.

Why is my memory almost full but the server is fine?

Linux uses spare memory as a file cache. Look at the available figure instead of free. If available is low and swap is heavily used, you have a real shortage.

Is kill -9 safe?

It stops the process at once, without letting it save or clean up. Try a normal kill first and use -9 only when the program does not respond.

Practise with interview questions