How to Use the Command 'procs' (with Examples)
‘procs’ is a versatile command-line tool designed to display information about active processes on a system. This tool provides users with insights into process details including the process ID (PID), the user who started the process, CPU usage, memory consumption, and the command that initiated each process. By offering an easy-to-read interface, ‘procs’ facilitates a deeper understanding of system performance and resource allocation.
Use case: List all processes showing the PID, user, CPU usage, memory usage, and the command which started them
Code:
procs
Motivation:
This basic use case provides a comprehensive overview of all active processes on a system. It is particularly useful for system administrators and users who want to obtain a quick snapshot of resource utilization and process activity without needing to input complex flags or parameters.
Explanation:
The command ‘procs’ without any additional arguments lists all active processes in the terminal. This includes displaying details such as the process ID (PID), the user who initiated the process, CPU utilization, memory consumption, and the command responsible for starting the process. By omitting additional filters or arguments, users can quickly assess the state of their system’s processes.
Example output:
PID User CPU MEM Command
1234 alice 0.1 5.0 /usr/bin/gnome-shell
5678 bob 1.2 2.5 /usr/lib/firefox/firefox
9101 charlie 0.0 1.2 /usr/bin/vim
Use case: List all processes as a tree
Code:
procs --tree
Motivation:
Visualizing processes as a tree structure helps users understand parent-child relationships between processes. This can be useful for debugging, resource management, or simply understanding how processes are interconnected within the system.
Explanation:
The ‘–tree’ argument modifies the display from a flat list to a hierarchical tree structure. This visual representation connects parent processes with their child processes, providing a clearer depiction of how processes are spawned and interact with one another.
Example output:
PID User CPU MEM Command
1 root 0.0 0.2 /sbin/init
├─ 1234 alice 0.1 5.0 /usr/bin/gnome-shell
├─ 5678 bob 1.2 2.5 /usr/lib/firefox/firefox
Use case: List information about processes, if the commands which started them contain Zsh
Code:
procs zsh
Motivation:
Filtering processes by a specific command can help users target specific applications or scripts, such as identifying all instances of a popular shell like Zsh. This is handy for system maintenance or when needing to manage or troubleshoot specific applications.
Explanation:
Including ‘zsh’ as an argument filters the list of processes to only those whose command line contains the substring ‘zsh’. This narrowing of focus is invaluable for users looking to manage or monitor specific processes efficiently, without being distracted by unrelated processes.
Example output:
PID User CPU MEM Command
2345 alice 0.1 0.3 /usr/bin/zsh
3389 bob 0.2 0.4 /bin/zsh -l
Use case: List information about all processes sorted by CPU time in ascending or descending order
Code:
procs --sorta|--sortd cpu
Motivation:
Sorting processes by CPU usage enables users to quickly identify which processes are most resource-intensive, helping to manage system performance and troubleshoot high CPU consumption issues. Users can choose to view processes in either ascending or descending order based on their preferences or specific requirements.
Explanation:
The ‘–sorta|–sortd cpu’ arguments instruct ‘procs’ to sort the displayed processes by CPU usage, with ‘–sorta’ for ascending and ‘–sortd’ for descending order. Sorting helps strategically identify bottleneck processes and manage system resources effectively.
Example output:
PID User CPU MEM Command
9101 charlie 0.0 1.2 /usr/bin/vim
1234 alice 0.1 5.0 /usr/bin/gnome-shell
5678 bob 1.2 2.5 /usr/lib/firefox/firefox
Use case: List information about processes with either a PID, command, or user containing 41
or firefox
Code:
procs --or PID|command|user 41 firefox
Motivation:
This use case is relevant when searching for specific processes where multiple criteria might apply. It allows users to specify diverse conditions and obtain a list of processes satisfying any one of those conditions, offering flexible process management.
Explanation:
The ‘–or PID|command|user 41 firefox’ arguments provide a way to filter processes using logical OR conditions. The command outputs processes where the PID, command, or user fields match either ‘41’ or ‘firefox’, offering a broad and flexible filtering mechanism catered to user needs.
Example output:
PID User CPU MEM Command
4141 alice 0.3 1.5 /usr/bin/zsh
5678 bob 1.2 2.5 /usr/lib/firefox/firefox
Use case: List information about processes with both PID 41
and a command or user containing zsh
Code:
procs --and 41 zsh
Motivation:
This use case exemplifies the need for more granular filtering by combining multiple conditions where all must be met. It helps users to pinpoint processes more accurately based on specific criteria such as a combination of PID and command attributes.
Explanation:
With ‘–and 41 zsh’, the command filters for processes meeting both specified conditions simultaneously. It captures processes whose PID is ‘41’ while the command or user fields must contain ‘zsh’, creating precise criteria that limit results strictly to deeply targeted processes.
Example output:
PID User CPU MEM Command
41 alice 0.1 0.3 /usr/bin/zsh
Conclusion:
The ‘procs’ command provides a powerful and flexible tool for monitoring and managing processes on a system. Its various options allow users to tailor the displayed information to their specific needs, whether for debugging, performance monitoring, or simple process management. By understanding and utilizing these use cases, users can significantly enhance their ability to control system processes efficiently.