Linux Task Displaying

LinuxLinuxBeginner
Practice Now

Introduction

Imagine a world where the digital landscape mirrors the harsh environment of a desert storm. Amid the cascading sands and chaotic winds, there is a character known as the "Sandstorm Maverick." This maverick is a renegade sysadmin, adept at navigating through tumultuous clusters of processes and services, ensuring the survival and optimal performance of critical servers.

In this lab, you will adopt the role of the Sandstorm Maverick. Your goal is to tame the storm of tasks running on a Linux system using the top command. By mastering top, you'll be able to identify resource-heavy processes and make informed decisions to manage system load effectively, ensuring that your servers stand firm, even in the most challenging conditions.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux/SystemInformationandMonitoringGroup -.-> linux/top("`Task Displaying`") subgraph Lab Skills linux/top -.-> lab-271407{{"`Linux Task Displaying`"}} end

Introduction to the top Command

In this step, you will familiarize yourself with the top command, the swiss army knife for task management in Linux. The top command displays real-time information about the system's processes, including CPU usage, memory consumption, and process statistics.

Navigate to your project directory and begin by executing the top command.

cd ~/project
top

Upon running top, you'll see a dynamic view of your system's process landscape. Take a moment to observe the display: the list of processes, the CPU and memory statistics at the top, and various other metrics.

To exit top, simply press q.

Now let's capture a static snapshot of the top processes using the -n 1 option to pass one iteration and output it to a file:

top -n 1 > top_snapshot.txt

This creates a file named top_snapshot.txt in the ~/project directory.

Interpreting the top Output

Now that you have a snapshot of the top processes, it's time to understand what the data tells you.

Open the top_snapshot.txt file using a text editor of your choice:

vim ~/project/top_snapshot.txt

Within the snapshot file, identify the following metrics for the process consuming the most CPU:

  1. PID (Process ID)
  2. USER (the owner of the process)
  3. %CPU (CPU usage percentage)
  4. %MEM (Memory usage percentage)
  5. COMMAND (The command or program running)

After reviewing the metrics, document your findings in a file named top_analysis.txt within the same directory.

echo "Most CPU-intensive process analysis" > ~/project/top_analysis.txt
echo "PID: [Insert PID]" >> ~/project/top_analysis.txt
echo "USER: [Insert USER]" >> ~/project/top_analysis.txt
echo "CPU%: [Insert %CPU]" >> ~/project/top_analysis.txt
echo "MEM%: [Insert %MEM]" >> ~/project/top_analysis.txt
echo "COMMAND: [Insert COMMAND]" >> ~/project/top_analysis.txt

Replace [Insert ...] with the actual values from your top_snapshot.txt file.

Summary

In this lab we have navigated through the harsh desert of running processes with the skilful use of the top command. You have learnt how to invoke top, take a snapshot of the current tasks and dissect the critical information to identify resource-intensive processes, much like Sandstorm Maverick would.