• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

ps Command Examples in Linux

by admin

The ps command invokes the process table, a record that summarizes the currently running processes on a system. When the command is run without any option, it displays the processes run by the current shell with details such as the PID, the terminal associated with the process, the accumulated CPU time, and the command that started the process. However, different options may be used along with the command to filter the displayed fields or processes.

Syntax

The syntax of the ps command is:

$ ps [options]

Command Option Syntax Styles

The ps command supports three different styles of command option syntax: Unix- style (preceded by a hyphen), GNU-style (preceded by two hyphens), and BSD-style (no hyphen). Mixing these styles will not always produce the same results. For example, the ps command (BSD-style) will print all processes with a controlling terminal, including session leaders (the first member of a group of processes). It will also print the status of each process, as well as the full command (including options) of each process. The ps -a command (Unix-style) also prints all processes with a controlling terminal, but does not include session leaders, the status of each process, nor the full command of each process.

ps Command Options

The ps command supports several options. Some of the more prominent options are listed here.

Option Used To
a List all user-triggered processes.
-e List all processes.
-l List processes using a long listing format.
u List processes along with the user name and start time.
r Exclude processes that are not running currently.
x Include processes without a terminal.
T Exclude processes that were started by any terminal other than the current one.
-U {user name} Display the processes based on the specified user.
-p {PID} Display only the process associated with the specified PID.
-C {command} Display all processes by command name.
–tty {terminal number} Display all processes running on the specified terminal.

ps Command Examples

1. To see the zombie process:

# ps aux | awk '{ print $8 " " $2 }' | grep -w Z

2. Listing zombie processes:

# ps -el | grep Z

3. To find/list the running processes:

# ps -r

4. Find processes for a particular user:

# ps -U apache
# ps U apache
# ps -u apache

5. To see every process running as root (real & effective ID) in user format:

# ps -U root u

6. To find/list the processes which has test.pl in its command execution:

# ps -f -C test.pl

7. List the processes based on PIDs:

# ps -f --ppid 9576

8. pgrep, pkill – look up or signal processes based on name and other attributes:

# pgrep 1234
# pkill 1234 OR # pkill httpd

9. Sorting the ps output:

# ps -eo uname,pid,ppid,nlwp,pcpu,pmem,psr,start_time,tty,time,args --sort -pcpu,-pmem

10. To print a process tree:

# ps -ejH
# ps axjf

11. Print only the process IDs of syslogd:

# ps -C syslogd -o pid=

12. Print only the name of PID 42:

# ps -p 42 -o comm=

13. List the Process based on the UID and Commands:

# ps -f -u wwwrun,postfix

14. List the processes based on PIDs or PPIDs:

# ps -f --ppid 9576

15. List Processes in a Hierarchy:

#  ps -e -o pid,args --forest

16. List elapsed wall time for processes:

# ps -p 1,29675 -o pid,etime=

17. To list the process hierarchy:

# ps -e -o pid,args --forest
# ps axjf
# ps -ejH

18. List all threads for a particular process:

# ps -C java -L -o pid,tid,pcpu,state,nlwp,args

19. To display a tree of processes:

# pstree

20. To list elapsed wall time for processes:

# ps -p 1,29675 -o pid,etime=

21. To get the process start time:

# ps -p PID -o lstart=

22. Display full information about each of the processes currently running:

# ps -ef | grep

23. To get info about threads:

# ps -eLf
# ps axms

24. To get security info:

# ps -eo euser,ruser,suser,fuser,f,comm,label
# ps axZ
# ps -eM

25. To see every process with a user-defined format:

# ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
# ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
# ps -eopid,tt,user,fname,tmout,f,wchan

26. List all threads for a particular process:

# ps -C java -L -o pid,tid,pcpu,state,nlwp,args

27. List all running processes including the full command string:

# ps auxww

28. Search for a process that matches a string:

# ps aux | grep string

29. List all processes of the current user in extra full format:

# ps --user $(id -u) -F

30. List all processes of the current user as a tree:

# ps --user $(id -u) f

31. Get the parent PID of a process:

# ps -o ppid= -p pid

32. Sort processes by memory consumption:

# ps --sort size

Filed Under: Linux

Some more articles you might also be interested in …

  1. UNIX / Linux : How to lock or disable an user account
  2. Audit Log And Messages File Not Rotating on CentOS/RHEL
  3. pvck Command Examples in Linux
  4. acpi Command Examples in Linux
  5. How to restrict ssh logins by user and client address on CentOS/RHEL
  6. How To Send Mails To an External User With Mailx on Linux
  7. elinks Command Examples in Linux
  8. kdocker: command not found
  9. SSSD Service Failing with “SSSD is already running” in CentOS/RHEL 7
  10. pkill Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright