procs (with examples)

procs (with examples)

Use Case 1: List all processes

procs

Motivation: This command is useful to get an overview of all the active processes running on the system and their key information. By default, it displays the PID (Process ID), user, CPU usage, memory usage, and the command that started the process.

Example Output:

PID    USER         CPU(%)    MEM(%)    COMMAND
123    john         0.5       1.2       chrome
456    jane         0.2       0.8       firefox
789    root         0.0       0.5       systemd

Use Case 2: List all processes as a tree

procs --tree

Motivation: Sometimes, it’s helpful to visually understand the process hierarchy on the system. The --tree option enables the display of processes as a tree structure, where child processes are indented under their respective parent processes.

Example Output:

123 chrome
    ├─ 234 chrome-sandbox
    ├─ 235 --type=zygote
    │   ├─ 236 --type=webgpu-process
    │   └─ 237 --type=utility --utility-subtype=network.mojom.BufferlessInputEventVoter
    ├─ 238 --type=zygote
    │   ├─ 239 --type=render
    │   │   └─ 240 --type=renderer --field-trial-handle=123
    │   │       ├─ 241 --type=utility --utility-subtype=network.mojom.BufferlessInputEventVoter
    │   │       ├─ 242 --type=utility --utility-subtype=network.mojom.BufferlessInputEventVoter
    │   │       └─ 243 --type=utility --utility-subtype=network.mojom.BufferlessInputEventVoter
    │   ├─ 244 --type=zygote
    │   └─ 245 --type=zygote
    └─ 246 --type=zygote-sandbox

Use Case 3: List processes by command filter

procs zsh

Motivation: When you are specifically interested in processes started by a particular command, you can use this command to filter the processes based on the command name.

Example Output:

PID    USER         CPU(%)    MEM(%)    COMMAND
123    john         0.5       1.2       zsh
234    jane         0.2       0.8       zsh
789    root         0.0       0.5       zsh

Use Case 4: List processes sorted by CPU time

procs --sorta|--sortd cpu

Motivation: To identify and analyze processes that consume the most CPU resources, sorting the processes list by CPU time can be helpful. The --sorta option sorts the processes in ascending order, while the --sortd option sorts them in descending order.

Example Output (Sorted in Ascending Order):

PID    USER         CPU(%)    MEM(%)    COMMAND
789    root         0.0       0.5       systemd
123    john         0.5       1.2       chrome
456    jane         0.2       0.8       firefox

Example Output (Sorted in Descending Order):

PID    USER         CPU(%)    MEM(%)    COMMAND
123    john         0.5       1.2       chrome
456    jane         0.2       0.8       firefox
789    root         0.0       0.5       systemd

Use Case 5: List processes using OR operator on filters

procs --or PID|command|user 41 firefox

Motivation: When you want to list processes that match any of the given filters, you can use the OR operator (|). In this example, the processes with PID 41 or command firefox are displayed.

Example Output:

PID    USER         CPU(%)    MEM(%)    COMMAND
41     john         0.3       1.1       firefox
123    jane         0.2       0.7       firefox

Use Case 6: List processes using AND operator on filters

procs --and 41 zsh

Motivation: In some cases, you might want to list processes that match multiple filters simultaneously. The AND operator is specified using a single --and argument. In this example, the processes with PID 41 and command/user zsh are displayed.

Example Output:

PID    USER         CPU(%)    MEM(%)    COMMAND
41     john         0.0       0.8       zsh

These examples demonstrate various ways to utilize the procs command to examine and understand the active processes on a system. Whether you need a simple overview, a tree-like view, or wish to filter and sort processes based on specific criteria, procs provides a versatile toolset for process analysis and management.

Related Posts

How to use the command taskset (with examples)

How to use the command taskset (with examples)

Taskset is a command used to get or set a process’ CPU affinity or start a new process with a defined CPU affinity.

Read More
How to use the command cargo yank (with examples)

How to use the command cargo yank (with examples)

This article will explain the various use cases of the cargo yank command, which is used to remove a pushed crate from the index.

Read More
How to use the command `ppmtotga` (with examples)

How to use the command `ppmtotga` (with examples)

ppmtotga is a command-line tool that converts PPM (Portable Pixmap) files to TGA (Targa) files.

Read More