ps command

 

ps (Process Status)

Purpose

The ps command is used to display information about the currently running processes on a system.
It shows details such as process ID (PID), terminal association, CPU usage, memory usage, and the command that started the process.


Basic Syntax

ps [options]

If used without any options, ps displays only the processes running in the current terminal session.


Common Examples

1. Basic Usage

ps

Output Example:

PID TTY TIME CMD 1234 pts/0 00:00:00 bash 1456 pts/0 00:00:01 ps

Explanation:

  • PID: Process ID — unique number assigned to each process

  • TTY: Terminal type (e.g., pts/0 → pseudo terminal)

  • TIME: Total CPU time used by the process

  • CMD: Command that started the process


2. View All Processes

ps -e

or

ps -A

Shows all processes running on the system (not just your terminal).


3. Detailed Information

ps -f

Output Example:

UID PID PPID C STIME TTY TIME CMD user 1234 1200 0 09:12 pts/0 00:00:00 bash user 1456 1234 0 09:13 pts/0 00:00:00 ps -f

Additional columns:

  • UID: User who owns the process

  • PPID: Parent Process ID (which process started this one)

  • C: CPU utilization percentage

  • STIME: Start time of the process


4. All Processes in Full Format

ps -ef

or

ps aux

Displays a snapshot of all processes with full details.

Difference between the two:

  • ps -ef → System V style output

  • ps aux → BSD style output

Example:

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 10000 2000 ? Ss 09:00 0:01 /sbin/init user 2345 1.2 2.3 250000 45000 ? Sl 09:10 0:05 /usr/bin/firefox

Key columns:

  • %CPU: CPU usage percentage

  • %MEM: Memory usage percentage

  • VSZ: Virtual memory size

  • RSS: Resident Set Size (actual physical memory used)

  • STAT: Process state (e.g., S=sleeping, R=running, Z=zombie, T=stopped)


5. View Process Tree

ps -ef --forest

Displays processes in a hierarchical tree structure showing parent-child relationships.


6. Search for a Specific Process

ps -ef | grep firefox

Shows only processes related to a particular program or keyword (here, “firefox”).


7. Display Processes for a Specific User

ps -u username

Lists all processes owned by the given user.


8. Show Process IDs Only

ps -C processname -o pid=

Example:

ps -C firefox -o pid=

Outputs only the PID(s) of processes named "firefox".


🧾 Process States (STAT column)

SymbolMeaning
RRunning
SSleeping
DUninterruptible sleep (usually I/O)
TStopped by job control signal
ZZombie (terminated but not cleaned up)

💡 Tips 

  • The ps command provides a snapshot of processes — it does not update continuously.

  • For continuous monitoring, use top or htop.

  • Combine ps with grep to search specific processes efficiently.


Program to try

simple and useful shell script that uses the ps command to display the top 5 processes consuming the most CPU and memory


🧩 Script: process_report.sh

#!/bin/bash # A simple script to display top 5 CPU and memory consuming processes echo "=======================================" echo " TOP 5 CPU-CONSUMING PROCESSES" echo "=======================================" ps -eo pid,ppid,user,cmd,%cpu --sort=-%cpu | head -n 6 echo echo "=======================================" echo " TOP 5 MEMORY-CONSUMING PROCESSES" echo "=======================================" ps -eo pid,ppid,user,cmd,%mem --sort=-%mem | head -n 6

output

=======================================
   TOP 5 CPU-CONSUMING PROCESSES
=======================================
    PID    PPID     USER         CMD                                     %CPU
    893       1             root         /usr/bin/containerd                  0.4
   1122       1            root         /usr/sbin/dockerd -Hfd://         0.4
2164398 2164291   binuvp   /usr/libexec/gvfs-udisks2-v      0.3
   1016     896          project2 /usr/libexec/gvfs-udisks2-v      0.3
   2262       1             root       /usr/bin/containerd-shim-ru      0.1

=======================================
   TOP 5 MEMORY-CONSUMING PROCESSES
=======================================
    PID    PPID     USER     CMD                                 %MEM
   1923    1867     root     /bin/ollama serve                    3.6
    888       1         root     /usr/sbin/tailscaled --stat         0.5
   1122       1        root     /usr/sbin/dockerd -H fd://       0.3
    387       1         root     /lib/systemd/systemd-journa  0.2
   3071    3030     root     next-server                              0.2

Comments