ps

2024-02-19

Understanding the Basics

The simplest form of the ps command displays a concise list of processes:

ps

This typically shows the process ID (PID), Terminal (TTY), and command name. However, ps’s true power lies in its numerous options, allowing for highly customized output.

Key Options and Their Usage

Let’s look at some essential ps options:

ps -e
ps -ef
ps -u john
ps -fx
ps -eo pcpu,pid,%mem,%cpu --sort=-%cpu
#This sorts by CPU usage in descending order (- signifies descending)
ps -aux | grep chrome  #Shows all chrome processes

This command first uses ps -aux (similar to ps -e, showing all processes and detailed information) and then pipes the output to grep which filters it to show only lines containing “chrome”.

ps -eo pid,%mem,%cpu | awk '{print $1 " " $2 " " $3}'
#This extracts PID, %MEM, and %CPU and prints them in a simplified format.

This example shows how awk can isolate specific columns and arrange them.

Going Deeper: Understanding Output Columns

The output columns often include:

By mastering the ps command and its various options, you gain a powerful tool for diagnosing performance bottlenecks, identifying resource-intensive processes, and troubleshooting system issues on your Linux systems. Effective use of grep and awk further enhances its analytical capabilities.