A comprehensive guide to using the ps
command in Linux to list and manage running processes.
At any given time, your computer is running numerous processes. To inspect and manage these processes, the ps
command comes in handy. It provides a list of the processes currently running in the system.
The displayed list represents the user-initiated processes in the current session. For example, you may see multiple instances of the fish
shell, mainly opened by VS Code within the editor, and an instance of Hugo running the development preview of a site. However, to list all processes, we need to include specific options when using ps
.
One of the most commonly used options is ax
: ps ax
.
The a
option lists processes from all users, not just the current one, while x
shows processes not linked to any terminal (i.e., those not initiated by users through a terminal).
By default, the output may truncate long command names. To display the full command, use ps axww
:
Note that w
needs to be specified twice to apply the line-wrapping setting. This avoids command truncation in the output.
To search for specific processes, you can combine ps
with the grep
command using a pipe:
ps axww | grep "VS Code"
The columns returned by ps
represent essential information about the processes.
- The first column is the
PID
, which stands for Process ID. You can use this ID to reference the process in other commands, such as killing it. - The
TT
column displays the terminal ID used by the process. - The
STAT
column represents the state of the process, where each letter indicates a specific state (e.g.,R
for a runnable process,T
for a stopped process, andZ
for a dead process). - Additional letters in the
STAT
column provide further technical information about the process. - The
+
symbol signifies that the process is in the foreground in its terminal, whiles
indicates that the process is a session leader.
The TIME
column indicates how long the process has been running.
It’s important to note that the ps
command works on Linux, macOS, WSL, and any UNIX environment.