Basic CLI: Monitoring Processes EffectivelyMastering Process Monitoring and Management in Linux

Introduction

Managing and monitoring processes is a crucial skill for system administrators and developers working in a Linux environment. Whether you need to check running processes, monitor system performance, or terminate misbehaving applications, the command line interface (CLI) provides powerful tools to get the job done efficiently.

In this guide, we’ll explore essential CLI commands for process monitoring and management, including ps, top, kill, pkill, and killall. You’ll learn their syntax, use cases, and best practices to keep your system running smoothly.

Viewing Running Processes with ps

The ps command allows you to view running processes and their details. By default, it shows only processes that belong to the current user. To see all processes, including those run by other users, use the following options:

ps

This command displays the processes initiated by the current user.

ps -ef

This command provides a full list of all processes running on the system, including their process IDs (PIDs), owners, and commands used to start them.

Real-Time Process Monitoring with top

The top command provides a real-time, dynamic view of all running processes, their CPU and memory usage, and system performance metrics.

top

Once inside top, you can:

  • Press q to quit.
  • Press k and enter a PID to kill a process.
  • Press r to change the priority of a process.

For a more user-friendly version, use htop if installed.

Managing Processes with kill

The kill command allows you to send signals to processes using their PIDs. The default signal is SIGTERM (15), which asks the process to terminate gracefully. If a process is unresponsive, use SIGKILL (9) to force termination.

kill <PID>

Example:

kill 1234

This sends a termination signal to process ID 1234.

To force-kill a process:

kill -9 1234

This ensures the process is stopped immediately.

Stopping Processes by Name with pkill

The pkill command is useful when you don’t know the exact PID but need to terminate a process by name.

pkill http*

This stops all processes that start with http, such as Apache's httpd service.

Killing Multiple Processes with killall

The killall command is similar to pkill, but it ensures all instances of a process name are terminated at once.

killall httpd

This stops all httpd processes running on the server.

For a forceful termination:

killall -9 httpd

This force-kills all httpd processes without waiting for graceful termination.

Conclusion

Understanding process monitoring and management in Linux is essential for system stability and performance optimization. The commands covered in this guide—ps, top, kill, pkill, and killall—offer powerful ways to track, analyze, and control running processes.

By mastering these CLI tools, you can efficiently manage your system, diagnose performance issues, and ensure applications run smoothly. Keep practicing, and soon, managing processes will become second nature!