4.3 Where Data is Stored (Weight: 3)
📘Linux Essentials (LPI 010-160)
1. What is a Process?
- A process is basically a program that is running.
- Examples of processes:
- Running a text editor like
geditornano. - A web server process like
apache2. - A backup script running automatically at night.
- Running a text editor like
- Each process has:
- A unique ID called PID (Process ID).
- Memory usage: How much RAM it is using.
- CPU usage: How much processor power it is using.
- State: Running, sleeping, stopped, etc.
2. Viewing Processes
Linux provides commands to see which processes are running:
ps(Process Status)- Shows current running processes.
- Example: ps aux
a– shows all users’ processesu– shows user/ownerx– includes background processes
top- Real-time monitoring of processes.
- Shows CPU and memory usage for each process.
- Example output columns:
- PID – Process ID
- USER – Owner of process
- %CPU – CPU usage
- %MEM – Memory usage
- COMMAND – Name of program
htop(if installed)- Better, interactive version of
top. - You can scroll, sort, and kill processes easily.
- Better, interactive version of
3. Process States
A process can be in different states:
| State | Meaning |
|---|---|
| R (Running) | Actively using CPU |
| S (Sleeping) | Waiting for input or a resource |
| T (Stopped) | Paused (manual or system signal) |
| Z (Zombie) | Finished but still in process table |
IT example: A web server process may sleep while waiting for a request from a user.
4. Memory Usage in Linux
Memory is where data is stored temporarily while processes are running. In Linux, memory usage is split into:
- RAM (Random Access Memory)
- Stores active processes and data temporarily.
- Faster than storage drives.
- Swap Space
- Extra memory on disk used when RAM is full.
- Slower than RAM.
- Cached Memory
- Linux keeps frequently used data in memory for faster access.
- It’s free for processes if needed.
5. Checking Memory Usage
Linux provides tools to see memory usage:
free- Shows RAM and swap usage.
- Example: free -h
-hmakes it human-readable (GB/MB)
- Output: total used free shared buff/cache available
8G 3G 2G 0.1G 3G 4.5G
toporhtop- Also shows memory per process.
- Useful for spotting processes using too much memory.
vmstat- Shows detailed memory, CPU, and process stats.
- Example: vmstat 2 5
- Updates stats every 2 seconds, 5 times.
6. Managing Processes
Sometimes you may need to stop or restart a process:
kill- Stop a process using its PID.
- Example: kill 1234
1234is the PID of the process.
killall- Stop all processes by name.
- Example: killall firefox
niceandrenice- Control CPU priority for processes.
- Example: Giving a backup script lower CPU priority: nice -n 10 ./backup.sh
7. IT Examples of Process & Memory Management
- Web server (Apache/Nginx):
- Each request can start a new process/thread.
- System memory must be monitored to avoid crashes.
- Database server (MySQL/PostgreSQL):
- Heavy queries may consume a lot of RAM.
- Swap may be used if RAM is full, slowing down performance.
- Automated backup scripts:
- Scheduled via
cron. - Low CPU priority using
niceto avoid slowing other services.
- Scheduled via
8. Key Exam Points
For LPI 010-160, you need to know:
- What a process is and PID.
- How to view processes (
ps,top,htop). - Process states (R, S, T, Z).
- Memory types: RAM, swap, cache.
- Commands to check memory (
free,vmstat,top). - How to manage processes (
kill,killall,nice,renice).
Summary Table for Quick Revision
| Topic | Command / Info |
|---|---|
| View processes | ps aux, top, htop |
| Process ID | PID |
| Process states | R, S, T, Z |
| Memory usage | free -h, top, vmstat |
| Stop process | kill PID, killall name |
| Change CPU priority | nice, renice |
