Bird
Raised Fist0
Linux CLIscripting~5 mins

top and htop (live monitoring) in Linux CLI - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sometimes your computer feels slow or you want to see what programs are using the most power. The tools top and htop help you watch your computer's activity live, showing which programs use the most memory and CPU.
When your computer is running slow and you want to find which program is causing it.
When you want to check how much memory or CPU your programs are using right now.
When you need to stop a program that is stuck or using too much power.
When you want to watch your system's activity during a heavy task to see how it behaves.
When you want a simple way to see all running programs and their resource use.
Commands
This command starts the top tool, showing a live list of running programs and their CPU and memory use.
Terminal
top
Expected OutputExpected
top - 15:00:00 up 1 day, 3:22, 2 users, load average: 0.15, 0.10, 0.05 Tasks: 120 total, 1 running, 119 sleeping, 0 stopped, 0 zombie %Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 92.0 id, 1.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8000000 total, 2000000 free, 3000000 used, 3000000 buff/cache KiB Swap: 2000000 total, 2000000 free, 0 used. 4000000 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1234 user 20 0 500000 30000 10000 S 5.0 0.4 0:10.00 myapp 5678 user 20 0 400000 20000 8000 S 2.0 0.3 0:05.00 bash
This command starts htop, a colorful and easier-to-use version of top with interactive controls.
Terminal
htop
Expected OutputExpected
htop - Interactive process viewer [Colorful display with CPU bars, memory bars, and a list of processes] Use arrow keys to navigate, F9 to kill a process, F10 to quit.
If htop is not installed, this command will show an error. You can install it with your package manager.
Terminal
htop
Expected OutputExpected
bash: htop: command not found
This command installs htop on Debian/Ubuntu systems so you can use it.
Terminal
sudo apt-get install htop
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: htop 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 100 kB of archives. After this operation, 300 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal/universe amd64 htop amd64 2.2.0-2build1 [100 kB] Fetched 100 kB in 1s (100 kB/s) Selecting previously unselected package htop. (Reading database ... 200000 files and directories currently installed.) Preparing to unpack .../htop_2.2.0-2build1_amd64.deb ... Unpacking htop (2.2.0-2build1) ... Setting up htop (2.2.0-2build1) ... Processing triggers for man-db (2.9.1-1) ...
→
sudo - Run the command with administrator rights needed for installation
Key Concept

If you remember nothing else from this pattern, remember: top and htop show live system activity so you can find and manage resource-heavy programs easily.

Common Mistakes
Trying to run htop without installing it first
The system will say 'command not found' because htop is not installed by default on many systems.
Install htop using your system's package manager before running it.
Not using sudo when installing htop
Without sudo, the install command will fail due to lack of permissions.
Use sudo before the install command to get administrator rights.
Confusing top's keyboard commands with htop's
top and htop have different keys for actions like killing a process, which can cause confusion.
Learn the specific keys for each tool; for example, htop uses F9 to kill a process.
Summary
Use 'top' to see a live list of running programs and their resource use.
Use 'htop' for a more user-friendly, colorful, and interactive system monitor.
Install htop with 'sudo apt-get install htop' if it is not already available.

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