You are on page 1of 8

25 Linux PS Command Examples,every System Admin Must Know

Every Program,which runs on linux system, we call it as process.Each process will have its own
unique process id. We can find out which process currently it is running on the system using
PS command.

With PS command,we can find out how many resources it is using like memory and
cpu.Sometimes,few processes will take more amount of resources which leads to System slow
Problems.One can identify these kind of problems using the PS command.

25 Linux PS Command Examples,every System Admin Must Know


Lets go by usage examples of PS Command.

Usage 1: PS command without options.

SLTMachine: # ps

PID TTY TIME CMD

6350 pts/2 00:00:00 ps

25025 pts/2 00:00:00 su


25026 pts/2 00:00:00 bash

It is basic usage of ps,it displays information about PID ( process id),TTY(machine where it is
executed),TIME(how long it is running),CMD(What command it is running).

Usage 2:Print every process on the linux.

SLTMachine: # ps -e

PID TTY TIME CMD

1 ? 00:00:02 init

2 ? 00:00:09 migration/0

3 ? 00:00:00 ksoftirqd/0

Usage 3:Print every process launched by the user srinivas on the machine.

SLTMachine: # ps -elf -u root

F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD

4 S root 1 0 0 76 0 - 183 410374 2016 ? 00:00:02 init [5]

1 S root 2 1 0 -40 - - 0 migrat 2016 ? 00:00:09 [migration/0]

1 S root 3 1 0 94 19 - 0 ksofti 2016 ? 00:00:00 [ksoftirqd/0]

1 S root 4 1 0 -40 - - 0 migrat 2016 ? 00:00:03 [migration/1]

Usage 4:Print every process launched by the group called administrators on the machine.

SLTMachine: # ps -elf -g administrators

It will give the information about processes launched by the group administrators only.
Usage 5: print only name of the pid 5678

SLTMachine ## ps -p 5678 -o comm=

Usage 6:Print process launched by its process id on the machine.

SLTMachine # ps -f -p 6800

UID PID PPID C STIME TTY TIME CMD

root 6800 1 0 2016 ? 00:00:03 gnome-power-manager --sm-disable

Each process is identified by its unique id.with the above command,i am trying find out the
process which has process id 6800

Usage 7:Print process launched by its parent process id on the machine.

SLTMachine # ps -f --ppid 1

UID PID PPID C STIME TTY TIME CMD

root 2 1 0 2016 ? 00:00:09 [migration/0]

root 3 1 0 2016 ? 00:00:00 [ksoftirqd/0]

root 4 1 0 2016 ? 00:00:03 [migration/1]

root 5 1 0 2016 ? 00:00:00 [ksoftirqd/1]

root 6 1 0 2016 ? 00:00:02 [migration/2]

Every process will create sub process,it it is required.Like root process will kick start all the
other applications on the machine.

In the above command,i am trying to find out processes launched by root process 1.

Usage 8:Print process launched by its name id on the machine.


SLTMachine # ps -C virus

I am trying to findout the process called virus here.

Usage 9: sort process launched by its cpu on the machine

SLTMachine # ps aux --sort=-pcpu

(or)

SLTMachine # ps aux --sort=+pcpu

(Here +/- denotes the ascending or descending order)

Usage 10: sort process launched by its memory on the machine

SLTMachine # ps aux --sort=-pmem

(or)

SLTMachine # ps aux --sort=+pmem

(Here +/- denotes the ascending or descending order)

Usage 11: Display threads of a process

SLTMachine # ps -p 2230 -L

Here -L gives information of of the threads of a process id 2230


Usage 12: Display threads of a process

SLTMachine #watch -n 1 'ps -e -o pid,ppid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head


-15'

Every 1.0s: ps -e -o pid,ppid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -15 Sun Mar 12


09:27:34 2017

PID PPID USER CMD %MEM %CPU

17615 25026 root watch -n 1 ps -e -o pid,ppi 0.0 0.5

17215 25026 root watch -n 1 ps -e -o pid,una 0.0 0.2

4649 4641 root /usr/X11R6/bin/X :0 -audit 0.3 0.0

236 15 root [pdflush] 0.0 0.0

6703 1 root /opt/gnome/lib/gnome-applet 0.3 0.0

237 15 root [pdflush] 0.0 0.0

4369 1 root /usr/sbin/nscd 0.0 0.0

3625 1 root /usr/sbin/vmtoolsd 0.0 0.0

5278 1 root /opt/CAB/SharedComponents/Sy 0.0 0.0

1234 15 root [reiserfs/1] 0.0 0.0

1236 15 root [reiserfs/3] 0.0 0.0

21 15 root [kblockd/0] 0.0 0.0


4401 1 root zmd /usr/lib/zmd/zmd.exe -- 0.0 0.0

5655 1 root /opt/CAB/SharedComponents/dt 0.9 0.0

The above command output refresh for every one second and its display the top 5 rows.Most
useful command for administrators.

Usage 13: Display parent process and child process relation

SLTMachine # ps -f --forest -C java

the above command search for process called java construct a tree

Usage 14: find process information of all the process ids available in set of process ids.

SLTMachine # ps -p 2001,2002,3001

Above command displays information about the process id is equal to 2001,2002 and 3001

Usage 15: give different names to existing ps column names.

SLTMachine # ps -e -o
pid,uname=USERNAME,pcpu=CPU_CONSUMPTION,pmem=MEMORY,comm=COMMAND

PID USERNAME CPU_CONSUMPTION MEMORY COMMAND

1 root 0.0 0.0 init

2 root 0.0 0.0 migration/0

3 root 0.0 0.0 ksoftirqd/0

4 root 0.0 0.0 migration/1

5 root 0.0 0.0 ksoftirqd/1

6 root 0.0 0.0 migration/2


7 root 0.0 0.0 ksoftirqd/2

Usage 16: display elapsed time of processes.

SLTMachine # ps -e -o pid,etime

PID ELAPSED

1 75-13:24:23

2 75-13:24:21

3 75-13:24:21

4 75-13:24:21

5 75-13:24:21

how long process has been running for

Usage 17: display all the process information.

SLTMachine ## ps ax

( Or )

SLTMachine ## ps -ef

we can use either of the command to display all the processes which are running.

Usage 18: find out whether given process is running or not


SLTMachine ## ps -elf|grep "process name"

Above command searches for the process in the list of all available processes.

Usage 19: print security information of the process ids

SLTMachine## ps -eo pid,user,args

Please run the above command,if you want to know,who is logged into the machine and what is
the process id of the process which he launched.

Usage 20: Print only processes associated only to this terminal

SLTMachine## ps T

Usage 21: Print Full listing iinformation of the processes

SLTMachine## ps -ef

Usage 22: Print Full listing information of the processes using page by page using more

SLTMachine## ps -ef | more

Usage 23: Print Full listing information of the processes using page by page using less

SLTMachine## ps -ef | less

Usage 24: Print process IDs of syslogd

SLTMachine## ps -C syslogd -o pid=

Usage 25: Print highest CPU utilisation in ascending order

SLTMachine## ps -aux --sort -pcpu | less

You might also like