The ps command on linux(UNIX too) is one of the most basic commands for viewing the processes running on the system. It provides a snapshot of the current processes along with detailed information like user
id, cpu usage, memory usage, command name etc.  Thus, it's an essential process
 management/monitoring tool that every linux admins should know.

Here are just few quick examples:
Note: The version of ps used in below examples accepts several kinds of options:

       1   UNIX options, which may be grouped and must be preceded by a dash.
       2   BSD options, which may be grouped and must not be used with a dash.
       3   GNU long options, which are preceded by two dashes.

 Note that "ps -aux" is distinct from "ps aux".  The POSIX and UNIX standards require that "ps -aux" print
       all processes owned by a user named "x", as well as printing all processes that would be selected by the
       -a option.  If the user named "x" does not exist, this ps may interpret the command as "ps aux" instead
       and print a warning.  This behavior is intended to aid in transitioning old scripts and habits.  It is
       fragile, subject to change, and thus should not be relied upon.

Sounds like complicated, but don't worry, most of process selection options are additive.  The default selection is discarded, and then the selected processes are added to the set of processes to be displayed.  A process will thus be shown if it meets any of the given selection criteria.It is okay to mix both the syntax styles on linux systems.
Here are examples:

Display all processes

The following command will give a full list of processes

$ ps ax
$ ps -ef
$ ps -eF

Use the "u" option or "-f" option to display detailed information about the processes

$ ps aux
$ ps -ef -f

where

    -e to display all the processes.
    -f to display full format listing.
a  Lift the BSD-style "only yourself" restriction, which is imposed upon the set of all
processes when some BSD-style (without "-") options are used or when the ps personality
setting is BSD-like.

Note: For all usernames (including yours) if the length is greater than 8 characters then ps will fall back to show only the UID instead of username.

Display process by user

To filter the processes by the owning user use the "-u" option followed by the username. Multiple usernames can be provided separated by a comma.

# ps -f -u postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  5917     1  0 Sep02 ?        00:02:33 /usr/pgsql-9.4/bin/postgres -D /var/lib/pgsql/9.4/data
postgres  5918  5917  0 Sep02 ?        00:00:01 postgres: logger process   
postgres  5920  5917  0 Sep02 ?        00:04:11 postgres: checkpointer process   
postgres  5921  5917  0 Sep02 ?        00:00:27 postgres: writer process   
postgres  5922  5917  0 Sep02 ?        00:00:57 postgres: wal writer process   
postgres  5923  5917  0 Sep02 ?        00:01:15 postgres: autovacuum launcher process   
postgres  5924  5917  0 Sep02 ?        00:04:57 postgres: stats collector process   

Show process by name

To search the processes by their name or command use the "-C" option followed by the search term.

# ps -l -C systemd
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
4 S     0     1     0  0  80   0 - 11093 ep_pol ?        00:00:42 systemd

'-l' option provides long format

The "-C" must be provided with the exact process name and it cannot actually search with a partial name or wildcard. To search the process list more flexibly, the usual grep command has to be used

$ ps -ef | grep postgres

Show process by process id

To display processes by process id, use the "-p" option and provides the process ids separated by comma.

$ ps -f  -p 3150,7298,6544

Display threads of a process

The "-L" option will display the threads along with the processes. It can be used to display all threads of a particular process or all processes.

The following command shall display all the threads owned by the process with id 21818, a java process.

# ps -p 21818 -L |wc
   2139   10695   74864

Sort process by cpu usage

System administrators often want to find out processes that are consuming lots of memory or CPU. The sort option will sort the process list based on a particular field or parameter.

Multiple fields can be specified with the "--sort" option separated by a comma. Additionally the fields can be prefixed with a "-" or "+" symbol indicating descending or ascending sort respectively
. There are lots of parameters on which the process list can be sorted. Check the man page for the complete list.

$ ps aux --sort=-pcpu

Display the top 5 processes consuming most of the cpu.

$ ps aux --sort=-pcpu | head -5
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
...

Sort process by memory usage

$ ps aux --sort=-pmem | head -5
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
...

In the above ps command, –sort option outputs the highest %MEM at bottom.

Display process hierarchy in a tree style

Many processes are actually forked out of some parent process, and knowing this parent child relationship is often helpful. The '--forest' option will construct an ascii art style tree view of the process hierarchy.

The following command will search for processes by the name postgres and construct a tree and display detailed information.

# ps -f --forest -C postgres
UID        PID  PPID  C STIME TTY          TIME CMD
postgres  5917     1  0 Sep02 ?        00:02:33 /usr/pgsql-9.4/bin/postgres -D /var/lib/pgsql/9.4/data
postgres  5918  5917  0 Sep02 ?        00:00:01  \_ postgres: logger process   
postgres  5920  5917  0 Sep02 ?        00:04:11  \_ postgres: checkpointer process   
postgres  5921  5917  0 Sep02 ?        00:00:27  \_ postgres: writer process   
postgres  5922  5917  0 Sep02 ?        00:00:57  \_ postgres: wal writer process   
postgres  5923  5917  0 Sep02 ?        00:01:15  \_ postgres: autovacuum launcher process   
postgres  5924  5917  0 Sep02 ?        00:04:57  \_ postgres: stats collector process   

Try not to use any sorting with the tree style display, as they both effect the order of display in different ways.

Display child processes of a parent process

Here is an example of finding all forked postgres processes.

# ps -o pid,uname,comm -C postgres
  PID USER     COMMAND
 5917 postgres postgres
 5918 postgres postgres
 5920 postgres postgres
...
25911 postgres postgres
26310 postgres postgres
26343 postgres postgres

The first process that is owned by root is the main postgres process and all other processes have been forked out of this main process. The next command lists all child apache2 processes using the pid of the main apache2 process

# ps --ppid 5917
  PID TTY          TIME CMD
 5918 ?        00:00:01 postgres
 5920 ?        00:04:11 postgres
...
25910 ?        00:00:00 postgres

Specify the columns to display

The ps command can be configured to show a selected list of columns only. There are a large number of columns to to show and the full list is available in the man pages.

The following command shows only the pid, username, cpu, memory and command columns.

#  ps -e -o pid,uname,pcpu,pmem,comm | head
  PID USER     %CPU %MEM COMMAND
    1 root      0.0  0.0 systemd
    2 root      0.0  0.0 kthreadd
    3 root      0.0  0.0 ksoftirqd/0
    7 root      0.0  0.0 migration/0
    8 root      0.0  0.0 rcu_bh

It is possible to rename the column labels

$ ps -e -o pid,uname=USERNAME,pcpu=CPU_USAGE,pmem,comm

Display elapsed time of processes

The elapsed time indicates, how long the process has been running for. The column for elapsed time is not shown by default, and has to be brought in using the "-o" option

$ ps -e -o pid,comm,etime

Turn ps into an realtime process viewer

As usual, the watch command can be used to turn ps into a realtime process reporter.

$ watch -n 1 'ps -e -o pid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -15'
Every 1s: ps -e -o pid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -5  Wed Sep 21 00:39:21 2016

  PID USER     CMD                         %MEM %CPU
 5920 postgres postgres: checkpointer proc 12.9  0.0
21818 root     /bin/java -server -Xmx2048m  8.4  2.0
21699 root     /bin/java -server -Xmx1024m  6.9  1.7
21756 root     /bin/java -server -Xmx512m   4.5  0.4
21592 root     /bin/java -server -Xmx1024m  4.2  0.5

The output would be updated every 1 second to refresh the stats.