Ways To Use ‘ps’ Command in Linux

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

command in linux

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

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

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

Sort Processes by Process ID

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

Shows Specific Columns

With -o flag, you get particular output display options for results of ps command.

Read Also:-
11 Linux Apps You Must Install On Your PC11 Linux Apps You Must Install On Your...- Looking for great Linux apps for your computer? We have found the best in the lot. See our list...

6. Grep within Results

Command Name: ps -ef | grep worker

Grep within Results

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

Filter Processes through Usage

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

Name Column Headers Again

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

Display All Root Processes

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

Show Process Threads

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.

Must Read:-
Top 6 Alternatives To Ubuntu LinuxTop 6 Alternatives To Ubuntu LinuxSearching for better Ubuntu alternative? This article tells about 6 best linux distros that can be used instead of Ubuntu....

12. Exhibit Results In The Form Of Hierarchical Tree

Command Used: ps -e –forest

Exhibit Results In The Form Of Hierarchical Tree

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe Now & Never Miss The Latest Tech Updates!

Enter your e-mail address and click the Subscribe button to receive great content and coupon codes for amazing discounts.

Don't Miss Out. Complete the subscription Now.