Processes and jobs
Linux commands: ps
Learn how the Linux ps command lists running processes, how ps ax shows them all, and how to read columns like PID and STAT or filter the output with grep.
Your computer is running tons of processes, all the time. The ps command lets you see them.
On Linux, ps with no options lists the processes started from your current terminal. On macOS it lists the processes of every terminal you have open, so I add -T to only see the ones of this terminal:

Here I have the bash shell running in this terminal, and the ps -T command itself.
Those are only the processes tied to my user and my terminal. To list all processes we need to pass some options to ps.
The one I use most is ps ax. The list is very long, so here I piped it into less -S, which shows one screen at a time and cuts each line at the edge of the window (a > marks the cut lines):

The
aoption also lists other users’ processes, not just our own.xshows processes not linked to any terminal, like the system daemons that start at boot.
Run on its own in the terminal, ps ax also cuts the longer commands. Use ps axww to wrap the command on new lines instead of cutting it (here I added | head -n 10 to only show the first lines):

We need to write
w2 times to get this behavior, it’s not a typo.
That list is long. You can search for a specific process by piping it into grep:
ps axww | grep Dock

Now let’s look at the columns ps returns.
The first is PID, the process ID. This is the number you need to reference the process in another command, for example to kill it.
Then we have TT, the terminal the process is attached to.
STAT tells us the state of the process:
I a process that is idle (sleeping for longer than about 20 seconds)
R a runnable process
S a process that is sleeping for less than about 20 seconds
T a stopped process
U a process in uninterruptible wait
Z a dead process (a zombie)
If you see more than one letter, the second one adds further information, which can get very technical.
The common ones: + means the process is in the foreground in its terminal. s means the process is a session leader.
TIME is the CPU time the process has consumed so far, not how long ago it started. A server that sat idle for a week shows a tiny TIME.
Finally, COMMAND (CMD in the ps -T output) is the command that started the process, with its arguments.
This command works on Linux, macOS, WSL, and anywhere you have a UNIX environment
Lesson completed