While working with processes. This is useful if you know how to show process properties and the PS command is what
you use to do. So we have already seen it occasionally. Now let's talk about the different options that it has.
So PS is the main command to show running processes. From the command line you can
use PS aux to to show all processes, including the most useful information about these processes.
Or psfax, which shows parent child relations between processes.
PS has many options, so use any options that you want to get
your process information. You'll find more information in the man pages about it.
Now, as a tip, I should suggest that you consider piping PS output to other tools
like AWK and Sort and Cut to find the information about processes that you want.
Let's do a quick PS primer.
So I'm going to start with psaox. That's all my processes in the order
of pid, where the process that was started last will be listed last.
Now if I would use psaox pipe grep, then I
can filter on processes. We talked about this before.
In the result you can see the SSH process but also the grep command.
And if you don't like that very much, add grep v grep behind it so that you only see the process itself.
Now, PSAOx is one way of using PS. In fact, there's a funny story behind it.
Normally in Linux, command line options have a hyphen in front of them.
But in the history of Linux, back in the days of Unix, there were two main dialects.
In the BSD dialects, options could be used without hyphen.
In the System V dialect, options could be used with a hyphen.
NPS happens to be a BSD background. And because of that BSD background that was ported to Linux, you
can still use it either BSD way or System five way. And that means either with or without a
hyphen. And that is why psaux as well as PS AUX are both showing the same information.
You can also use PS E F, which is more a System 5 way
of doing it, and that is showing also a lot of information about processes.
Probably quite important to know is what exactly you see and you will find out if you pipe the
output of PSAOx to less there on the top row you can see everything that is displayed. So the
username, the process identifier, the CPU usage, the memory usage, virtual memory that is used and resident memory that
is used in kilobytes. And the resident memory is what really matters. Virtual memory is not so very important.
Skipping a few columns. Then we have the start time, when it was started, the amount of time it is used,
and the command itself. Now another command that I like a lot is psfaux that will show you a process forest.
And this forest is relevant because in processes there is always a parent child relation.
So here you can see that the psfaux command was started from a bash
shell and this bash shel is a part of the pty XIS command.
And using this parent child relationship might be convenient to figure out what exactly is going on.
Now you can also use PS with options that are quite advanced like
PS E o pid arcs minus forest which is showing options. And in
the options we have the process ID and we have the forest option.
Or what do you think of ps?
C SSHD L O PID
TID PCPU stage NLWPNRCS Wow,
that's a lot of options.
And what do we see in this output? Well, we see threads. If
you have a multi threaded process, you can go as deep as this.
I'm not expecting you to remember stuff like this, but I'm expecting you to know that
in PS there's a lot of options that allows you to filter information about specific processes.
Also a nice one is psaox sort PMEM
that will sort your processes by memory.
Let's filter it to less.
And there you get an overview of the memory usage. Lowest is first, so the bottom lines
are most interesting there you can see in the fourth column that gnome shell, apparently with 9.5%
memory, is the process that uses most of memory. And that's how you can use.