Introduction
This lab introduces essential Linux tools for managing processes and system resources. As a beginner, you'll learn how to use ps, top, and free commands to monitor and analyze system processes and memory usage. These tools are fundamental for understanding what's happening on your Linux system.
Achievements
By the end of this lab, you'll be able to:
- List and filter processes using
ps - Monitor processes in real-time with
top - Check system memory usage using
free
List All Processes
Let's start by listing all processes running on the system using the ps command.
Open your terminal. You should be in the
/home/labex/projectdirectory. If you're not sure, you can always check your current directory by typingpwdand pressing Enter.Run the following command to list all processes:
ps -eThis will display a list of all processes, including their Process ID (PID), terminal (TTY), CPU time, and command name.
Take a moment to examine the output. You'll see system processes and user processes. Here's what each column means:
- PID: The unique Process ID
- TTY: The terminal type associated with the process
- TIME: The amount of CPU time used by the process
- CMD: The command or program name
Don't worry if you see unfamiliar process names; many of these are system processes that run in the background.
Display Detailed Process Information
Now, let's get more detailed information about the processes.
Run the following command:
ps auxThis command shows a detailed list of all processes, including the user who started the process, CPU and memory usage, and the full command line.
The output might be quite long. You can use the
lesscommand to view it more easily:ps aux | lessThis pipes the output of
ps auxintoless, allowing you to scroll through it.In the
lessviewer:- Use the up and down arrow keys to scroll
- Press
Spaceto move forward one page - Press
bto move back one page - Press
qto exit thelessviewer when you're done
Let's break down what you're seeing:
- USER: The owner of the process
- PID: Process ID
- %CPU: CPU usage
- %MEM: Memory usage
- VSZ: Virtual memory size
- RSS: Resident Set Size (non-swapped physical memory used)
- TTY: Terminal type
- STAT: Process state
- START: Start time of the process
- TIME: Cumulative CPU time
- COMMAND: The command with all its arguments
Don't worry if you don't understand all of these right now. As you gain more experience, you'll become familiar with these terms.
Filter Processes by User
You can filter processes to show only those belonging to a specific user. This is useful when you want to focus on processes owned by a particular user account.
To see processes owned by the root user, run:
ps -u rootThe root user is the superuser in Linux systems, with full system access rights. Many system processes run under the root account.
To see processes owned by your current user (labex), run:
ps -u labexThis will show you all processes that you've started under your user account.
Compare the outputs of these two commands. You'll likely see more processes under root than under your user account.
Monitor Processes in Real-time with top
The top command provides a dynamic, real-time view of the running processes. It's like a live dashboard for your system.
Run the following command:
topYou'll see a continuously updating display of system processes, sorted by CPU usage. The display is divided into two main sections:
- The summary area at the top, showing system-wide information
- The process list, showing details of individual processes
While in
top, you can use various commands:- Press
Mto sort by memory usage instead of CPU - Press
Pto return to sorting by CPU usage - Press
Tto sort by running time - Press
Nto sort by PID - Use the up and down arrow keys to navigate the process list
- Press
qto quittop
- Press
The summary area includes important system information:
- System uptime and load averages
- Tasks summary (total, running, sleeping, stopped, zombie)
- CPU states (user, system, idle, etc.)
- Memory usage (total, free, used, buffers/cached)
- Swap usage
Take some time to explore top. It's a powerful tool for understanding what's happening on your system in real-time.
Check System Memory Usage
The free command allows you to check the system's memory usage quickly and easily.
Run the following command to see memory usage in a human-readable format:
free -hThe
-hoption stands for "human-readable", which displays the sizes in powers of 1024 (e.g., 1K, 234M, 2G).You'll see output similar to this:
total used free shared buff/cache available Mem: 7.7G 4.1G 287M 624M 3.3G 2.7G Swap: 2.0G 506M 1.5GLet's break down what each row and column means:
- Mem: This row shows information about your system's RAM
- Swap: This row shows information about your swap space (virtual memory)
Columns:
- total: Total installed memory
- used: Memory currently in use
- free: Unused memory
- shared: Memory shared by multiple processes
- buff/cache: Memory used by kernel buffers, page cache, and slabs
- available: Estimate of how much memory is available for starting new applications, without swapping
Don't be alarmed if your "free" memory seems low. Linux uses available memory for disk caching to improve system performance, but this memory can be reclaimed if needed by applications.
Summary
In this lab, you've learned how to use key Linux process management tools:
psto list and filter processestopto monitor processes in real-timefreeto check system memory usage
These commands are essential for system administration and troubleshooting. They give you insight into what's running on your system, how resources are being used, and can help you identify potential issues.
As you become more comfortable with these tools, you can explore additional options and combine them with other Linux commands for more advanced system analysis. For example:
- Use
pswithgrepto find specific processes - Learn to interpret the detailed information in
topto identify resource-intensive applications - Use
freein scripts to monitor memory usage over time
Remember, practice makes perfect! Don't hesitate to experiment with these commands on your own to deepen your understanding of Linux process management. The more you use these tools, the more intuitive they'll become.



