Hack 91. Ps Command Examples

by Ramesh

ps command (process status) will display snapshot information of all active processes.

Syntax: ps [options]

How to display all the processes running in the system?

Use “ps aux”, as shown below.

# ps aux | more
USER       PID %CPU %MEM    VSZ    RSS TTY  STAT START  TIME COMMAND
root               1       0.0         0.0    2044     588 ?        Ss        Jun27      0:00  init [5]         
apache   31186       0.0        1.6  23736 17556 ?        S          Jul26       0:40  /usr/local/apache2/bin/httpd
apache   31187       0.0        1.3  20640 14444 ?        S          Jul26       0:37  /usr/local/apache2/bin/httpd

You can also use “ps -ef | more”, to get a similar output

Print the Process Tree

You can use either ps axuf or ps –ejH to display processes in a tree format. The tree structure will help to visualize the process and it’s parent process immediately. For clarity purpose, few columns have been cut-off in the output below.

# ps axuf

root     Oct14   0:00 /opt/VRTSralus/bin/beremote
root     Oct14   0:00  \_ /opt/VRTSralus/bin/beremote
root     Oct14   0:00      \_ /opt/VRTSralus/bin/beremote
root     Oct14   0:00      \_ /opt/VRTSralus/bin/beremote
root     Oct14   0:01      \_ /opt/VRTSralus/bin/beremote
root     Oct 14  0:00      \_ /opt/VRTSralus/bin/beremote
root     Dec03   0:01 /usr/local/sbin/sshd
root     Dec22   1:08 /usr/local/sbin/sshd
root     23:35   0:00  \_ /usr/local/sbin/sshd
511      23:35   0:00      \_ -bash
511                           \_ ps axuf

Note: You can also use pstree command to display process in tree structure.

View Processes Owned by a Particular User

The following command displays all the process owned by Linux user-name: oracle.

$ ps U oracle

PID TTY      STAT   TIME COMMAND
5014 ?        Ss     0:01 /oracle/bin/tnslsnr
  7124 ?        Ss     0:00 ora_q002_med
8206 ?        Ss     0:00 ora_cjq0_med
8852 ?        Ss     0:01 ora_pmon_med
8854 ?        Ss     0:00 ora_psp0_med
8911 ?        Ss     0:02 oraclemed (LOCAL=NO)

View Processes Owned by Current User

Following command displays all the process owned by the current user.

$ ps U $USER

PID TTY      STAT   TIME COMMAND
10329 ?        S      0:00 sshd: ramesh@pts/1,pts/2
10330 pts/1    Ss     0:00 -bash
10354 pts/2    Ss+    0:00 -bash
10530 pts/1    R+     0:00 ps U ramesh

Leave a Comment

Previous post:

Next post: