DEV Community

Cover image for Process Monitoring: Keeping Systems in Check
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

5 3 3 3 3

Process Monitoring: Keeping Systems in Check

Process monitoring is the practice of continuously observing and analyzing system processes to maintain optimal performance, detect issues early, and ensure system stability.

It involves tracking resource utilization, execution states, and dependencies of running processes.

By leveraging process monitoring, system administrators and developers can proactively address bottlenecks, prevent failures, and optimize system resources.

Modern monitoring tools provide insights into CPU usage, memory consumption, input/output operations, and thread activity.

These tools often feature real-time dashboards, alerting mechanisms, and historical logging to facilitate efficient troubleshooting and capacity planning.

Essential Process Monitoring Tools

Several utilities help in tracking process activity in Linux-based systems.

Below are some widely used tools and their applications.

1. htop - Interactive Process Viewer

htop is an advanced interactive tool for monitoring system processes in real time. Unlike top, it offers a color-coded interface, supports scrolling, and allows users to manage processes directly within the interface.

Install htop:

sudo apt install htop  # Debian/Ubuntu
sudo yum install htop  # CentOS/RHEL
Enter fullscreen mode Exit fullscreen mode

Run htop:

htop
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Displays CPU, memory, and swap usage in a graphical format.
  • Allows killing or renicing processes directly.
  • Supports process filtering and sorting by different metrics.

htop

Check btop

2. pidstat - Resource Usage per Process

pidstat provides a breakdown of CPU, memory, I/O, and thread activity for each process, making it useful for diagnosing performance issues.

Install pidstat:

sudo apt install sysstat  # Debian/Ubuntu
Enter fullscreen mode Exit fullscreen mode

Track CPU usage by process:

pidstat -u 1
Enter fullscreen mode Exit fullscreen mode

Monitor disk I/O per process:

pidstat -d 1
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Reports CPU, memory, and I/O usage per process.
  • Helps in identifying processes causing high resource consumption.
  • Supports exporting data for historical analysis.

pidstat

3. strace - System Call Tracer

strace is invaluable for debugging and understanding how a process interacts with the system kernel.

Trace system calls of a running process:

strace -p <PID>
Enter fullscreen mode Exit fullscreen mode

Run a command with strace:

strace ls
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Tracks system calls and signals used by a process.
  • Helps diagnose slow performance or permission-related issues.
  • Useful for debugging unknown binary applications.

strace

4. lsof - List Open Files

Since Unix-like systems treat everything as a file, lsof helps track which files (including network sockets) are accessed by processes.

List all open files:

lsof
Enter fullscreen mode Exit fullscreen mode

Show files opened by a specific process:

lsof -p <PID>
Enter fullscreen mode Exit fullscreen mode

List processes using a specific port:

lsof -i :80
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Identifies files in use by processes.
  • Helps troubleshoot file access issues and network connections.
  • Assists in identifying processes locking a file or port.

lsof

5. ps - Snapshot of Running Processes

ps provides a static view of currently running processes, useful for scripting and one-time analysis.

List all running processes:

ps aux
Enter fullscreen mode Exit fullscreen mode

Filter by user:

ps -u <username>
Enter fullscreen mode Exit fullscreen mode

Display process tree:

ps -ef --forest
Enter fullscreen mode Exit fullscreen mode

Key Features:

  • Provides detailed information about running processes.
  • Useful for historical analysis and debugging.
  • Supports custom formatting and filtering.

ps

Automating Process Monitoring

For continuous monitoring, tools like Prometheus, Grafana, and Nagios are commonly used.

They collect system metrics, visualize data, and trigger alerts based on predefined thresholds.

Conclusion

Process monitoring is essential for ensuring the reliability, performance, and security of IT systems.

Whether using command-line utilities like htop, lsof, and pidstat or adopting advanced tools like Prometheus and Grafana, monitoring enables early detection of issues and helps optimize resource allocation.

Integrating automated alerts and historical logging further enhances system observability, making troubleshooting and maintenance more efficient.


I’ve been working on a super-convenient tool called LiveAPI.

LiveAPI helps you get all your backend APIs documented in a few minutes

With LiveAPI, you can quickly generate interactive API documentation that allows users to execute APIs directly from the browser.

image

If you’re tired of manually creating docs for your APIs, this tool might just make your life easier.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay