Tuesday, October 2, 2018

ps command examples

ps Command

ps command:- ps command is used to see current running processes.

1) Display currently running processes 
ps -ef

Note:-"-e" option is for displaying all the processes and "-f" option is for displaying full format listing.
                     (OR)
ps -aux
     
2) Display all running processes of a User
ps -f -u username

3) Display the processes based on PIDs or PPIDs   
ps -f --ppid 2359

ps -f  -p 4389,5268,9421

4) Display processes in Hierarchy
ps -f --forest

ps with grep and more for displaying selected data:-
5) Display processes which have a "string" word in its name
ps -eaf|grep string

6) Display the "ps -eaf" result pagewise
ps -ef|more
OR
ps -ef|less




ps with --sort option for sorting data:-
7) Display the "ps -eaf" result in sorted order of column
ps -eaf --sort pcpu
ps -eaf --sort pid
ps -eaf --sort ppid

Below following values can be put in "--sort" option
cmd     - Executable name
pcpu    - CPU utilisation
flags   - Flags
pgrp    - Process group id
cutime  - Cumulative user time
cstime  - Cumulative system time
utime   - User time
pid     - Process ID
ppid    - Parent process ID
size    - Size
uid     - User ID
user    - User Name

OR

ps aux --sort=-pcpu,+pmem

Note:- Here "+" denotaing increasing order and "-" denotaing decreasing order

8) Display the top 10 processes consuming most of the cpups aux sort=-pcpu |head -10

9) Display selected column 
ps -e -o pid,uname,pcpu,pmem,comm

Note:- "-o" option is used to display selected columns

10) Display "ps" result in realtime process viewer
watch -n 1 'ps -e -o pid,uname,cmd,pmem,pcpu --sort=-pmem,-pcpu | head -15'

Note:-Output would be updated every 1 second to refresh the stats.

No comments:

Post a Comment

Remove CTRL-M characters from a file in UNIX

 We can remove ^M by below methods 1st Method - Using sed command Type below command:    sed -e "s/^M//" filename > newfilena...