If you’re involved with managing servers, then you’ll already be aware of how little servers offer as far as user interfaces are concerned. Most of the work necessitates the use of the command line interface.

When monitoring servers, you often need to track multiple things simultaneously, such as disk usage, network, CPU temperatures, etc. While all of this information is best presented in a dashboard interface, many creative people have developed makeshift dashboards in the CLI that display information about your system as if you were using a graphical user interface.

By the end of this article, you will be able to use ps, top, htop, and atop, which are some of the most powerful command-line utilities that provide deep insights into system behavior.

Each tool has its strengths, and system administrators often combine them to get a comprehensive view of their systems.

Let’s get started!

The ps Command

The ps command is short for “process status”. It is a fundamental tool in Linux for viewing information about active processes.

The basic syntax for using the ps command is:

ps [options]

When run without any options, ps typically shows:

  • The processes associated with the current terminal session
  • The process ID (PID)
  • The terminal type (TTY)
  • The CPU time used
  • The command name
check running process in Linux using ps command

Suggested read: Mastering the Echo Command in Linux (with Practical Examples) 

Common Options and Flags

The ps command shows useful information, but you can use advanced options and flags to change its default behavior. Here’s a list of some of the possible options:

  1. -e or -A: Show all processes
  2. -f: Full format listing, providing more details
  3. -u username: Show processes for a specific user
  4. -p pid: Show information for a specific process ID
  5. –sort=[+|-]key: Sort the output. Use + for ascending, – for descending
  6. -o format: Customize the output format

Examples of ps Command Usage

The ps command is very flexible. You can mix and match the above flags to produce the desired output. For example:

  1. List all processes: ps -e
  2. Full format listing of all processes: ps -ef
  3. Show processes for a specific user: ps -u username
  4. Display processes sorted by CPU usage: ps -eo pid,ppid, cmd,%cpu,%mem --sort=-%cpu
  5. Display only the process IDs: ps -eo pid

Suggested read: Pipes vs Xargs: Which One To Use When Writing Bash Scripts In Linux 

The top Command

The top command is a real-time system monitoring tool that provides a dynamic, interactive view of a Linux system’s running processes. It displays system summary information and a list of processes or threads currently managed by the Linux kernel.

You can run the top command by executing the following in your terminal:

top

This command launches the top interface, which refreshes by default every 3 seconds.

check running process in Linux using top command

Understanding the top Interface

The top interface is divided into two main sections presenting different information. Here’s is a quick overview of both sections:

  1. Summary Area (top half):
    • System time and uptime
    • Number of users logged in
    • Load average (1, 5, and 15-minute averages)
    • Tasks summary (total, running, sleeping, stopped, zombie)
    • CPU usage breakdown (user, system, idle, etc.)
    • Memory usage (total, free, used, buffers/cache)
    • Swap usage
  2. Process List (bottom half):
    • PID: Process ID
    • USER: User who owns the process
    • PR: Priority
    • NI: Nice value
    • VIRT: Virtual memory used
    • RES: Resident memory used
    • SHR: Shared memory
    • S: Process status
    • %CPU: CPU usage
    • %MEM: Memory usage
    • TIME+: Total CPU time
    • COMMAND: Command name

Top Command Flags and Options

The top command also offers various flags and options that allow you to customize its behavior and output. Here are some of the most useful ones:

  1. -b (Batch mode): This runs top in batch mode, which is useful for sending output to other programs or a file.
  2. -n (Number of iterations): This parameter specifies the number of iterations before the top exits. It is useful in scripts or when capturing a specific number of samples.
  3. -p (Monitor specific PIDs): Shows only the processes with the specified PIDs.
  4. -u (Show specific user’s processes): Displays only the processes the specified user owns.
  5. -H (Show threads): Shows individual threads instead of processes.
  6. -o (Sort field): Sorts the process list by a specific field (e.g., CPU usage, memory usage). For example, top -o %CPU
  7. i (Ignore idle processes): Does not display idle or zombie processes.
  8. -c (Show command line): Displays the full command line for each process instead of just the command name.
  9. -d (Delay time): Sets the delay between updates (in seconds). The default is 3.0 seconds.

These flags can be combined for more specific outputs. For example, the following command will run top in batch mode for five iterations, sorts by memory usage, shows only the root’s processes, and sends the output to a file:

top -b -n 5 -o %MEM -u root > top_output.txt

Remember, you can also interactively use many of these options by pressing the corresponding key while top is running. For instance, pressing ‘h‘ toggles the thread view, ‘i‘ ignores idle processes, and ‘c‘ toggles the command line display.

The htop Command

htop is an interactive process viewer for Unix systems, designed as an enhanced alternative to the top command. It offers several advantages over other process viewers:

  1. User-friendly interface: Colorful and more intuitive than top.
  2. Mouse support: The mouse can be used to select and interact with the terminal.
  3. Tree view: Visualize process relationships.
  4. Easier process management: Kill processes without entering their PID.
  5. Built-in meters: Includes built-in CPU, memory, and swap usage meters.

Installing htop

htop is typically not pre-installed on most systems. Run the following command with the necessary permissions on your Ubuntu/Debian systems to install it:

sudo apt update && sudo apt install htop

After installation, you can launch htop by simply typing htop in the terminal.

check running process in Linux using htop command

Suggested read: How to Copy Files in Linux and Overwrite without Confirmation 

Using htop: interface and navigation

The htop interface is divided into two main sections:

  1. Header (top) section shows system-wide stats and meters
    • CPU usage (per-core and overall)
    • Memory usage
    • Swap usage
    • Tasks, load average, uptime
  2. Process list (bottom) shows detailed information about each process

The htop interface can be overwhelming at first glance, but once you learn to navigate it, you’ll get detailed information about your system with only a few key presses. Let’s see some keyboard actions and what they do on htop interface:

  • Up/Down arrows: Move through the process list
  • Left/Right arrows: Scroll horizontally for wide columns
  • Space: Tag/untag a process
  • U: Untag all processes
  • F3 or /: Search for a process
  • F4: Filter processes by name
  • F5: Tree view
  • F6: Sort by column
  • F9: Kill a process
  • F10 or q: Quit htop

Suggested read: Best 9 htop Alternatives for Linux, Mac & Windows in 2024 

Customizing htop display and settings

Like other command line utilities, you can pass some flags to htop to customize its output and display. For example, here is a list of commands with their corresponding effect@

  1. htop -t: Start in tree view
  2. htop -u username: Show only processes of a specific user
  3. htop -p PID1,PID2,...: Show only specified processes

The atop Command

atop (Advanced Top) is a powerful, interactive monitor that allows users to view the load on a Linux system. It shows the status of the most critical hardware resources (CPU, memory, disk, and network) at a system level. It has several unique features that set it apart from other monitoring tools:

  1. Persistent logging: atop can write snapshots to a log file for long-term analysis.
  2. Resource-specific views: It has dedicated screens for CPU, memory, disk, and network details.
  3. Cumulative reporting: It can show resource consumption since the system boot.
  4. Process accounting: It can also track short-lived processes that might be missed by interval sampling.

Suggested read: How to Find Most Used Disk Space Directories and Files in Linux 

Installing atop

atop is not pre-installed on most systems. You can run the following command to install it on most Ubuntu/Debian distributions:

sudo apt update && sudo apt install atop

After installation, the atop service typically starts automatically for continuous logging.

To view the atop interface, simply type atop in the terminal. This will open up a new screen where you will see the following information:

  1. System-level information:
    • Date, time, uptime, and number of systems
    • CPU statistics (user, system, idle, wait, etc.)
    • Memory and swap usage
    • Disk I/O statistics
    • Network statistics
  2. Process-level information:
    • PID: Process ID
    • SYSCPU: System CPU time
    • USRCPU: User CPU time
    • VGROW: Virtual memory growth
    • RGROW: Resident memory growth
    • RDDSK: Disk read activity
    • WRDSK: Disk write activity
    • ST: Process state
    • EXC: Exit code
    • CMD: Command name

atop is a powerful tool, and you can enjoy its powers once you learn to navigate it. Here’s a list of some of the basic commands that you can try to get started with atop:

  • t: Show detailed system and process statistics for one specific interval
  • c, m, d, n: Toggle between CPU, memory, disk, and network-specific views
  • v: Show program version info
  • z: Show only active processes (hide idle processes)
  • 1: Show average-per-CPU utilization
  • P, M, D: Sort by CPU, memory, or disk activity, respectively
  • q: Quit atop

Suggested read: Introduction to Bash For Loops: A Beginner’s Guide 

Final Thoughts: Simplifying System Monitoring with RunCloud

This post has covered some of the most common system monitoring tools for Linux servers. While command-line tools provide powerful and flexible monitoring capabilities, they still require a certain level of expertise to use effectively. Moreover, if you manage multiple servers or want a more user-friendly interface, these tools might not be enough for you.

This is where RunCloud comes into play. RunCloud’s dashboard simplifies server monitoring and management, making it accessible even to those without deep Linux expertise.

Here’s how RunCloud enhances your monitoring experience:

  1. Centralized Monitoring: Instead of logging into each server individually, you can monitor all your servers from a single dashboard.
  2. User-Friendly Interface: RunCloud presents complex system information in an easy-to-understand graphical interface, eliminating the need to interpret command-line output.
  3. Disk Usage Monitoring: Easily track disk usage across all your servers, helping you prevent disk space issues before they become critical.
  4. Slow Script Detection: RunCloud can identify slow-running scripts, a feature that typically requires setting up additional monitoring tools on your servers.
  5. Alerts and Notifications: Set up custom alerts for various metrics to notify you immediately of any issues.

Ready to simplify your server monitoring and management? Sign up for RunCloud today!