ps Command in Linux with Examples

ps Command

ps command is used to find the running processes of the system.
 

Syntax

ps
 

ps without any option

This is a very basic ps usage. It shows you process ID (PID), TTY command running place, Time and CMD.

Example

[user1@linuxhelp ~]$ps 
PID   TTY      TIME      CMD
7822  pts/3    00:00:00  su
7831  pts/3    00:00:00  bash
13061 pts/3    00:00:00  ps


This information is unsorted result.

 

Current Processes

The following command is used to view all the current running processes.
Option 'f' is used to display the detailed information about the process

 

Example

[user1@linuxhelp ~]$ ps ax 
PID  TTY       STAT    TIME  COMMAND
1     ?        Ss     0:01  /sbin/init
2     ?        S      0:00  [kthreadd]
3     ?        S      0:00  [migration/0]
4     ?        S      0:00  [ksoftirqd/0]
5     ?        S      0:00  [migration/0]
[user1@linuxhelp ~]$ ps -ef  -f 
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 09:14 ?        00:00:01 /sbin/init
root         2     0  0 09:14 ?        00:00:00 [kthreadd]
root         3     2  0 09:14 ?        00:00:00 [migration/0]
root         4     2  0 09:14 ?        00:00:00 [ksoftirqd/0]
root         5     2  0 09:14 ?        00:00:00 [migration/0]

 

Filter User Processes

The following command is used to filter a specific user processes

Example

[user1@linuxhelp ~]$ ps  -u  user1 
PID  TTY      TIME      CMD
3161 pts/0    00:00:00  bash
3345 pts/0    00:00:00  ps

 

Filter Processes by CPU or Memory usage

The following command is used to filter the processes by CPU or memory.

 

Example

[user1@linuxhelp ~]$ ps aux | less
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.1  0.0  19336   792 ?        Ss   09:14   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    09:14   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:14   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    09:14   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    09:14   0:00 [migration/0]

 

Sort processes by highest CPU utilization

The following command is used to sort the processes by highest CPU utilization.

 

Example

[user1@linuxhelp ~]$ ps aux --sort –pcpu | less 
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      3194 10.7 43.7 1198736 442508 ?      Sl   09:28   1:22 /usr/lib64/fire
fox/firefox
root      2336  1.6  6.5 164912 66060 tty1     Ss+  09:14   0:26 /usr/bin/Xorg :
0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-ruguYX/database -noliste
n tcp vt1
root      3094  0.8  7.2 1108696 73600 ?       Sl   09:25   0:07 /usr/lib64/libr
eoffice/program/soffice.bin --writer file:///root/Desktop/ps_commands.docx --spl
ash-pipe=7

To Sort processes by highest memory utilization

The following command is used to sort the processes by highest memory utilization.

 

Example

[user1@linuxhelp ~]$ ps aux --sort –pmem | less 
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  19336   960 ?        Ss   09:14   0:01 /sbin/init
root         2  0.0  0.0      0     0 ?        S    09:14   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:14   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    09:14   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    09:14   0:00 [migration/0]

Filter Processes by name

The following command is used to filter processes by name.

 

Example

[user1@linuxhelp Desktop]# ps  -C  init 
PID TTY          TIME CMD
1 ?        00:00:01 init
[user1@linuxhelp Desktop]# ps -f -C firefox
UID        PID  PPID  C STIME TTY          TIME CMD
root      3194     1  9 09:28 ?        00:04:10 /usr/lib64/firefox/firefox


To show it in a full formatting list option -f option can be used along with it.

 

Process Thread

The following command is used to view the thread of the particular process.

 

Example

[user1@linuxhelp Desktop]# ps  -L  3194 
 PID   LWP TTY      STAT   TIME COMMAND
 3194  3194 ?        Sl     3:36 /usr/lib64/firefox/firefox
 3194  3213 ?        Sl     0:00 /usr/lib64/firefox/firefox
 3194  3214 ?        Sl     0:04 /usr/lib64/firefox/firefox
 3194  3215 ?        Sl     0:11 /usr/lib64/firefox/firefox
 3194  3216 ?        Sl     0:03 /usr/lib64/firefox/firefox
 3194  3217 ?        Sl     0:00 /usr/lib64/firefox/firefox
 3194  3218 ?        Sl     0:00 /usr/lib64/firefox/firefox

 

Processes Hierarchy

The following command is used to view the processes in hierarchical form.

 

Example

[user1@linuxhelp Desktop]# pstree 
init???NetworkManager
     ??abrtd
     ??acpid
     ??atd
     ??auditd???{auditd}
     ??automount???4*[{automount}]
     ??bonobo-activati???{bonobo-activat}
     ??certmonger
     ??clock-applet
     ??console-kit-dae???63*[{console-kit-da}]
[user1@linuxhelp ~]$ ps  axjf 
 PPID   PID  PGID   SID TTY      TPGID STAT   UID   TIME COMMAND
    0     2     0     0 ?           -1 S        0   0:00 [kthreadd]
    2     3     0     0 ?           -1 S        0   0:00  \_ [migration/0]
    2     4     0     0 ?           -1 S        0   0:00  \_ [ksoftirqd/0]
    2     5     0     0 ?           -1 S        0   0:00  \_ [migration/0]
    2     6     0     0 ?           -1 S        0   0:00  \_ [watchdog/0]
    2     7     0     0 ?           -1 S        0   0:04  \_ [events/0]
    2     8     0     0 ?           -1 S        0   0:00  \_ [cgroup]
    2     9     0     0 ?           -1 S        0   0:00  \_ [khelper]
    2    10     0     0 ?           -1 S        0   0:00  \_ [netns]

 

User Running the application

The following command is used to view the user who’s the running the application with PID.

 

Example

[user1@linuxhelp ~]$ ps -eo pid,user,args 
PID USER     COMMAND
  1 root     /sbin/init
  2 root     [kthreadd]
  3 root     [migration/0]
  4 root     [ksoftirqd/0]
  5 root     [migration/0]

Thank you! for using Linux Help.

You find this tutorial helpful? Share with your friends to keep it alive.
For more help topics browse our website www.linuxhelp.com
Be the first to comment, we value your suggestions. For further queries please comment below.

Tags: Ps
user image Author :  Jayce