In the Linux operating system, the ps program is the most common tool used by a system administrator. It provides a real-time glimpse at the list of running processes.
The syntax of ps can be a bit different. We have listed some of the best ways you can ps command along with a single dash as it is most used syntax.
Let’s get Started!
1. Show All Processes
Command Used: ps -ef
This will show currently running processes along with the data related to every process. The data also consists of columns displaying PID, terminal type, command name and time running.
2. Filter Processes By Process Name
Command used – ps -C name
You will display processes by the process name. All the process name will be in lower case. It will search via all processes without -eprefix.
3. Sort Processes By User
Command Used: ps -e -u
You can filter ps results to get processes under a particular username. You can also use it without prefix.
4. Sort Processes by Process ID
Command 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.
5. Shows Specific Columns
ps -e -o pid,uname,pcpu,pmem,comm
With -o flag, you get particular output display options for results of ps command.
6. Grep within Results
Command Name: ps -ef | grep worker
If you want to pliability to search inside the results from ps, you can pipe the results to grep. With this command (grep), you can search via usual expressions for pattern-matching.
7. Filter Processes through Usage
Command Used: ps -e –sort=-pcpu -o pid,pcpu,comm
It filters command using listed columns. The – prefix classifies the feature in decreasing order and the + prefix filters the feature in increasing order. The command also has -o command which displays specific columns, however, it is not essential for sorting
8. Mix & Match Renamed and Default Name Columns
Command 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. Also, if you want to mix & match renamed and default name columns, then you need -o flag for each renamed column.
9. Name Column Headers Again
Command Used: ps -o pid=Process,ruser=RealUser,comm=Command
You can rename the columns while using -o command which creates a user-specified output appearance. All you need to do is attach = sign and the desired name and -o flag for every renamed header.
10. Display All Root Processes
Command 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.
11. Show Process Threads
Command 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.
12. Exhibit Results In The Form Of Hierarchical Tree
Command Used: ps -e –forest
With ASCII art, it creates a tree-like structure to show processes. It displays forked & children processes as successors of the relevant processes, classing to match. If you want to hide “branches” of the tree, replace –forest to -H
So, these are some of the combination commands which can be used with ps command to get information about the processes running and also can display information in useful formats.