Skip to end of metadata
Go to start of metadata

Monitoring Processes With ps

Category: Getting Started &nbsp

The importance of being able to see what the processes on your system are doing can never really be understated. It’s pretty much expected that at some point you’ll be staring at a terminal screen scratching your head wondering why something isn’t quite working right, it happens to all of us at some point.

One of the more helpful tools for when that situation arises is ps. As with many of the tools on Linux, ps traces its history back to the UNIX days before Linux existed. It was designed to show a process status of the system. Invoking ps couldn’t be much simpler, and is as follows…


Well that was easy, though not very informative. On its own ps will simply show us any processes related to the current terminal session, so chances are all you can see are a process for bash (the shell used to preset that command prompt), and another process for ps.

This is fairly useless unless you know that what you are looking for is a process related to this session.  ps takes a number of flags providing a huge amount of customisation of the output you’ll be presented with, to the point that reading them all makes it feel a bit like casting runes. So lets take a look at what is probably the most used incantation…

ps aux

That will most likely give an output that filled a few screen’s worth of text. To give an overview of what you just typed, the a tells ps to show all processes including other users, u tells it to present the output in a user oriented output, and x tells ps to also show processes that don’t have a control terminal (i.e. process started automatically by the system).

Experiment with those letters a bit and you’ll see that ax shows the same number of processes in the same format as just the plain ps command. ux shows only processes for your user but in the same format as ps aux.  A fairly helpful improvement of the output with the u flag is that usernames are shown rather than user ids, while Linux deals with user ids for everything rather than names, names are somewhat easier for humans to associate with.

There are a few other flags I also tend to find useful…

f           This flag causes ps to show the relationship between processes, so you can easily see which processes are children of others.

-e         This flag also tells ps to select all processes, so you may see some places using -e uf as opposed to aux to view a process tree

l           This flag tells ps to present the output in long format,

Something to bear in mind here is that ps’ response to some flags differs depending on whether they are prefixed with a hyphen or not. For example, here are three virtually similar commands…

            ps -e uf

            ps euf

            ps -euf

Now on the face of it you would expect three similar outputs, but in fact the output you receive varies massively, something to bear in mind. I’d recommend experimenting a bit with the flags and then memorising combinations that suit you. For further output customisation, you can also use the -o flag to customise the output of ps with columns you want to see rather than any of the standard outputs, for example…

ps -o pid,user,pcpu,stime,time,args

This can be used with the other flags such as -e,a,x,f,etc as it just specifies a custom output. Below is a list of some the common argument names, the matching column name and meaning of each entry…

Argument         Column          Meaning

pid                  PID                  process id number

uid                  UID                  user id number

user                 USER               username

pcpu               %CPU              percentage of CPU currently used by the process

pmem             %MEM             percentage of memory currently used by the process

stime               STIME             process start time

time                TIME               CPU time used by the process since starting

etime              ELAPSED        the time elapsed since the process was started

args                 COMMAND      command string with full arguments shown

comm             COMMAND      the program name the process belongs to

nice                NI                     the nice value of the process

tty                   TTY                 the terminal that the process belongst to

stat                  STAT               the process status

As said, that list isn’t exhaustive, the main page for ps contains more information but that should be enough for most events.

Personally I’d suggest spending time getting to know ps and its outputs and putting together an alias to call ps with a custom output can be very handy if you prefer such a thing. As with anything else, the more familiar you get with the command the easier it will be to use when you need it in anger.

Save this article