Linux top
Command
In the realm of Linux and Unix-like operating systems, monitoring system
performance and managing processes are critical aspects of system
administration. The top
command is a powerful and versatile
tool
that provides real-time insights into system performance. It allows users to
view and manage processes, track system resource usage, and analyze system
behavior in real time. In this blog post, we will explore the
top
command in depth, covering its syntax, options, features, and practical
applications.
Basic Syntax
The basic syntax of the top
command is simple:
bashtop
This will launch the top
command in its default mode, displaying
real-time system statistics and a dynamic list of processes.
Displaying System Performance
When you run top
, it provides a dynamic display that
continuously
updates to show system performance metrics. The default view includes
information such as CPU usage, memory usage, load averages, and the list of
running processes.
Displaying Process Information
The process list displays information about each running process, including the process ID (PID), user, CPU and memory usage, process status, and more. The processes are sorted by various criteria, usually by CPU usage by default.
Sorting the Process List
You can sort the process list based on different criteria by pressing specific keys. For instance:
- Press
P
to sort by CPU usage. - Press
M
to sort by memory usage.
Filtering the Process List
top
allows you to filter the displayed processes based on
criteria
such as user, command, or process ID. Press O
and then specify
the
filtering criteria.
Killing Processes
While running top
, you can send signals to processes and
terminate
them. Press k
, enter the PID of the process you want to
terminate,
and press Enter.
Practical Applications
-
Monitoring System Performance: To get a real-time overview of system performance, including CPU and memory usage.
bashtop
-
Analyzing Process Behavior: To analyze the behavior of specific processes and their resource consumption.
bashtop -p <PID>
-
Killing Misbehaving Processes: To terminate misbehaving or unresponsive processes.
bashtop (identify the PID of the misbehaving process) k