Bird
Raised Fist0
Linux CLIscripting~10 mins

top and htop (live monitoring) in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - top and htop (live monitoring)
Start top or htop command
↓
System info displayed
↓
Processes list updated live
↓
User can interact (htop)
↓
Exit command to stop monitoring
The flow shows starting the command, displaying system info and live process updates, user interaction (htop), and exiting.
Execution Sample
Linux CLI
top
htop
Run 'top' or 'htop' to see live system resource usage and process list.
Execution Table
StepCommandActionOutput/State
1topStart top commandDisplays CPU, memory, tasks summary and process list updating every few seconds
2topAuto-refreshProcess list and system stats refresh live showing current usage
3htopStart htop commandDisplays colorful, interactive process list with CPU bars and memory usage
4htopUser interactionUser can scroll, sort, kill processes using keyboard
5top or htopExit command (q)Monitoring stops, returns to shell prompt
💡 User presses 'q' to quit top or htop, ending live monitoring
Variable Tracker
VariableStartAfter 1 refreshAfter 2 refreshFinal
CPU Usage %variesupdates liveupdates liveupdates live until exit
Memory Usagevariesupdates liveupdates liveupdates live until exit
Process Listinitial snapshotupdated listupdated listupdated list until exit
Key Moments - 3 Insights
Why does the process list keep changing every few seconds in top?
Because top refreshes the process list live to show current CPU and memory usage, as seen in execution_table rows 1 and 2.
What extra feature does htop have compared to top?
htop allows user interaction like scrolling and killing processes with keyboard, shown in execution_table row 4.
How do you stop the live monitoring in top or htop?
Pressing 'q' quits the program and returns to the shell, as shown in execution_table row 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 3 when running htop?
AExits the monitoring tool
BDisplays a static list of processes
CDisplays colorful, interactive process list with CPU bars
DStarts a system update
💡 Hint
Refer to execution_table row 3 describing htop output
At which step does the user interact with the process list in htop?
AStep 1
BStep 4
CStep 2
DStep 5
💡 Hint
Check execution_table row 4 about user interaction
If the user presses 'q' during top or htop, what happens according to the execution table?
AThe monitoring stops and returns to shell
BThe process list refreshes faster
CThe system reboots
DNothing happens
💡 Hint
See execution_table row 5 about exit command
Concept Snapshot
top and htop commands show live system resource usage and processes
 top is basic, auto-refreshing every few seconds
 htop is colorful and interactive with keyboard controls
 Press 'q' to quit either tool
 Useful for monitoring CPU, memory, and running processes live
Full Transcript
The top and htop commands are tools to monitor your Linux system live. When you run top, it shows CPU, memory, and process info that updates every few seconds automatically. htop is similar but adds color and lets you interact with the list using keyboard keys to scroll or kill processes. Both keep updating the process list live until you press 'q' to quit and return to the shell prompt. This live updating helps you see how your system resources change over time and which processes use the most CPU or memory.

Practice

(1/5)
1. What is the main purpose of the top command in Linux?
easy
A. To display live system and process information
B. To edit text files
C. To compile programs
D. To manage user accounts

Solution

  1. Step 1: Understand the function of top

    The top command shows real-time information about system processes and resource usage.
  2. Step 2: Compare with other options

    Options B, C, and D relate to different commands or tools, not top.
  3. Final Answer:

    To display live system and process information -> Option A
  4. Quick Check:

    top = live system info [OK]
Hint: Remember: top shows live system stats [OK]
Common Mistakes:
  • Confusing top with text editors like nano
  • Thinking top manages users
  • Assuming top compiles code
2. Which of the following commands correctly starts htop in the terminal?
easy
A. start htop
B. htop -start
C. htop &
D. run htop

Solution

  1. Step 1: Identify correct syntax to run htop

    The command htop runs the program; adding & runs it in background.
  2. Step 2: Check other options for correctness

    Options B, C, and D are not valid Linux commands to start htop.
  3. Final Answer:

    htop & -> Option C
  4. Quick Check:

    Run htop with 'htop &' [OK]
Hint: Run htop by typing 'htop' or 'htop &' [OK]
Common Mistakes:
  • Using invalid flags like -start
  • Typing 'start htop' which is Windows style
  • Using 'run htop' which is not a Linux command
3. You run top and see a process using 95% CPU. What does this indicate?
medium
A. The process is waiting for user input
B. The process is sleeping and not active
C. The process is stopped
D. The process is using most of the CPU power

Solution

  1. Step 1: Interpret CPU usage in top

    High CPU percentage means the process is actively using CPU resources.
  2. Step 2: Understand other states

    Sleeping or waiting processes use little CPU; stopped processes do not use CPU.
  3. Final Answer:

    The process is using most of the CPU power -> Option D
  4. Quick Check:

    High CPU% = active process [OK]
Hint: High CPU% means active process using CPU [OK]
Common Mistakes:
  • Thinking high CPU means sleeping
  • Confusing waiting with stopped
  • Assuming stopped processes use CPU
4. You try to run htop but get: command not found. What should you do?
medium
A. Restart the computer
B. Install htop using the package manager
C. Run top instead
D. Check if you typed htop correctly

Solution

  1. Step 1: Understand 'command not found' error

    This means htop is not installed or not in PATH.
  2. Step 2: Fix by installing htop

    Use package manager like sudo apt install htop or sudo yum install htop to install.
  3. Final Answer:

    Install htop using the package manager -> Option B
  4. Quick Check:

    command not found = install missing tool [OK]
Hint: Install missing commands with package manager [OK]
Common Mistakes:
  • Restarting without installing
  • Ignoring the error and running top
  • Not checking spelling before install
5. You want to find and kill the process using the most memory using htop. What steps should you follow?
hard
A. Sort by memory, select process, press F9 to kill
B. Sort by CPU, select process, press F10 to kill
C. Sort by PID, select process, press F3 to kill
D. Sort by user, select process, press F5 to kill

Solution

  1. Step 1: Sort processes by memory usage in htop

    Press F6 or click the memory column to sort descending by memory.
  2. Step 2: Select the top memory-consuming process and kill it

    Use arrow keys to select process, then press F9 to kill it.
  3. Final Answer:

    Sort by memory, select process, press F9 to kill -> Option A
  4. Quick Check:

    htop kill = sort mem + F9 [OK]
Hint: In htop, F9 kills selected process after sorting [OK]
Common Mistakes:
  • Using wrong function keys to kill
  • Sorting by CPU instead of memory
  • Trying to kill by PID without selecting
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard