0
0
Linux-cliHow-ToBeginner · 3 min read

How to Use ps Command in Linux: Syntax and Examples

The ps command in Linux shows running processes on your system. Use ps aux to see all processes with details, or ps -ef for a full-format listing.
📐

Syntax

The basic syntax of the ps command is:

  • ps [options] - Runs the command with specified options.
  • ps aux - Lists all running processes with user, CPU, memory, and command info.
  • ps -ef - Shows a full-format listing including parent process IDs.
bash
ps [options]
ps aux
ps -ef
💻

Example

This example shows how to list all running processes with detailed info using ps aux. It displays user, PID, CPU and memory usage, start time, and the command that started the process.

bash
ps aux
Output
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 169084 5564 ? Ss 10:00 0:01 /sbin/init user 2345 0.1 1.2 256000 25000 pts/0 Ss 10:05 0:10 /usr/bin/bash user 2378 0.0 0.5 150000 10000 pts/0 R+ 10:06 0:00 ps aux
⚠️

Common Pitfalls

Common mistakes when using ps include:

  • Running ps without options shows only processes in the current shell session.
  • Confusing BSD-style options (like aux) with UNIX-style options (like -ef).
  • Not using ps with grep properly to find processes, which can include the grep command itself.
bash
ps
ps aux | grep ssh
ps aux | grep '[s]sh'
📊

Quick Reference

OptionDescription
auxShow all processes with detailed info (BSD style)
-efShow all processes in full format (UNIX style)
-u usernameShow processes for a specific user
-p PIDShow process with specific PID
--sortSort processes by a field, e.g., %cpu or %mem

Key Takeaways

Use ps aux to see all running processes with details.
Use ps -ef for a full-format process list including parent IDs.
Without options, ps shows only current shell processes.
Use ps aux | grep '[p]attern' to avoid matching the grep process itself.
Remember BSD and UNIX style options differ; choose based on your needs.