Hack 91. Ps Command Examples

by Ramesh

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

  1. Syntax: ps [options]

How to display all the processes running in the system?

Use “ps aux”, as shown below.

  1. # ps aux | more
  2. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
  3. root 1 0.0 0.0 2044 588 ? Ss Jun27 0:00 init [5]
  4. apache 31186 0.0 1.6 23736 17556 ? S Jul26 0:40 /usr/local/apache2/bin/httpd
  5. 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.

  1. # ps axuf
  2.  
  3. root Oct14 0:00 /opt/VRTSralus/bin/beremote
  4. root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
  5. root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
  6. root Oct14 0:00 \_ /opt/VRTSralus/bin/beremote
  7. root Oct14 0:01 \_ /opt/VRTSralus/bin/beremote
  8. root Oct 14 0:00 \_ /opt/VRTSralus/bin/beremote
  9. root Dec03 0:01 /usr/local/sbin/sshd
  10. root Dec22 1:08 /usr/local/sbin/sshd
  11. root 23:35 0:00 \_ /usr/local/sbin/sshd
  12. 511 23:35 0:00 \_ -bash
  13. 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.

  1. $ ps U oracle
  2.  
  3. PID TTY STAT TIME COMMAND
  4. 5014 ? Ss 0:01 /oracle/bin/tnslsnr
  5. 7124 ? Ss 0:00 ora_q002_med
  6. 8206 ? Ss 0:00 ora_cjq0_med
  7. 8852 ? Ss 0:01 ora_pmon_med
  8. 8854 ? Ss 0:00 ora_psp0_med
  9. 8911 ? Ss 0:02 oraclemed (LOCAL=NO)

View Processes Owned by Current User

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

  1. $ ps U $USER
  2.  
  3. PID TTY STAT TIME COMMAND
  4. 10329 ? S 0:00 sshd: ramesh@pts/1,pts/2
  5. 10330 pts/1 Ss 0:00 -bash
  6. 10354 pts/2 Ss+ 0:00 -bash
  7. 10530 pts/1 R+ 0:00 ps U ramesh