Run ps without any optionsThis is a very basic ps usage. Just type ps on your console to see its result.
Show All ProcessesCommand Used: ps -ef
This will show the current running processes along with the data related to every process. The data consists of columns displaying PID, terminal type, command name and time running.
Filter Processes By Process NameCommand used – ps -C name
You will display processes by the process name, which will be in lower case. It will search via all processes without -eprefix.
Sort Processes By UserCommand Used: ps -e -u
You can filter ps results to get processes under a particular username. You can also use it without prefix.
Sort Processes by Process IDCommand Used: ps -ef -p 1234,5678,9012
If you know what is process ID of a certain running process, you can filter it by using process ID.
Shows Specific Columnsps -e -o pid,uname,pcpu,pmem,comm
With -o flag, you get particular output display options for results of ps command.
Grep within ResultsCommand Name: ps -ef | grep worker
If you want to search inside the results from ps, you can pipe the results to grep. With this command you can search via usual expressions for pattern-matching.
Filter Processes through UsageCommand Used: ps -e –sort=-pcpu -o pid,pcpu,comm
It filters command using listed columns. The – prefix filters the feature in decreasing order and the + prefix filters the feature in increasing order. The command also has -o command which displays specific columns.
Mix & Match Renamed and Default Name ColumnsCommand Used: ps -e -o pid,pcpu=CPU -o pmem=RAM,comm
If you wish to hide the headers in specific columns, then you can leave a blank just after = sign. If you want to mix & match renamed and default name columns, then you need -o flag for each renamed column.
Name Column Headers AgainCommand Used: ps -o pid=Process,ruser=RealUser,comm=Command
You can rename the columns using -o command. You need to attach = sign and the desired name and -o flag for every renamed header.
Display All Root ProcessesCommand Used: ps -f -U root -u root
It runs a search for all running processes with original and efficient root identifications. With -f flag, you can get format in full-length. To get customize the output, you can add -o flag to it.
Show Process ThreadsCommand Used: ps -p 4041 -L
Use -L flag to toggle on thread display to get any functionality of ps. This is used to track down the threads of a particular process.
Exhibit Results In The Form Of Hierarchical TreeCommand Used: ps -e –forest
It creates a tree-like structure to show processes. It displays forked & children processes as successors of the relevant processes. If you want to hide “branches” of the tree, replace –forest to -H