11 Uses for the ‘ps’ Command in Linux

Use Ps On Linux Hero

For system administrators, ps is a frequently-used tool. It’s used to list the currently-running processes on your system with a variety of filter and display modes available through flags and arguments.

The syntax of ps can be subtly odd. We will follow the UNIX convention of a single dash preceding a flag since that’s by far the most widely-supported syntax. However, it can also be run with BSD syntax, which drops prefixed dashes and uses a separate flag name syntax. For example, the aux flag replaces the more common -ef flag. Make sure you know which one you’re using.

1. Show All Processes

Use Ps On Linux Ef Flag

Shows all running processes with full data about every process. This data includes columns showing the PID, terminal type (TTY), time running, and command name.

2. Filter by User

Filters ps results to only show processes owned by the specified username. Can also be used without the prefix.

3. Filter by Process Name

Use Ps On Linux C Flag

Filters the results by the process name. The search is not case sensitive, but all process names are in lower case at any rate. Will search through all processes without the -e prefix.

4. Filter by Process ID

If you know the process ID of the running process you want to show, you can filter for it specifically with the -p flag. This can take multiple PIDs as arguments, separated by a single comma and no space.

5. Grep within Results

Use Ps On Linux Grep

If you want more flexibility to search within the results from ps, you can pipe the results to grep. While this is more of a combination of commands than a pure ps command, it’s a regular part of any administrator’s tool belt. With grep, you can search using regular expressions for pattern-matching and more.

6. Display Specific Columns

Use Ps On Linux O Flag

The -o flag sets specific output display options for the ps command’s results. See a full list of standard display options for ps.

7. Sort Processes by Usage

Sorts commands by the listed columns. The minus (-) prefix sorts that feature in descending order, while the plus (+) prefix sorts in ascending order. This command also uses the -o command to display specific columns, which is not strictly necessary for sorting.

8. Rename Column Headers

Use Ps On Linux Rename Headers

When using the -o command to create a user-specified output appearance, columns can be renamed. Add an = (equal) sign and the desired name, using a -o flag for each renamed header. Headers can also be hidden in specific columns by leaving a blank after the equal sign. You can mix and match with renamed and default name columns. Just be sure to use a -o flag for each renamed column as shown below:

9. Display Results in Hierarchical Tree Style

Uses ASCII art to create a tree-style structure for displaying processes. Shows forked and children processes as descendants of the appropriate parent processes, sorting to match. To hide the “branches” of the tree, use -H in place of --forest.

10. Display Process Threads

Use Ps On Linux L Threads Flag

The -L flag toggles on thread display for any functionality of ps. It’s most useful when tracking down the threads of a specific process.

11. Show All Root Processes

Use Ps On Linux Root Processes 2

Execute a search for all processes running with real and effective root identifications. This shows them in the full-length format thanks to the -f flag. You can combine it with the -o flag to customize output.

Conclusion

While the UNIX style flags fit in better with other Terminal commands, the BSD commands can display information in different and, sometimes, more useful formats. If you’re interested in learning about the BSD-style flags, check out the ps man page.

One comment

  1. Excellent! I love the approach!

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.