Golden Codes - armanexplorer planet

Practical code snippets for Django, Python, Bash, Git and All!

View on GitHub

The ps command is a versatile tool in Linux for viewing information about running processes. Here's how you can use it to get details about process status:

Basic Usage:

By default, ps displays information about the processes associated with your current terminal session. It provides a limited set of columns:

$ ps
  PID TTY          TIME CMD
 18756 pts/0    00:00:00 bash
 20146 pts/0    00:00:00 ps

Getting More Information:

Examples:

# List all processes with full format
$ ps -f

# List processes owned by user "root"
$ ps -u root

# Filter processes by name (shows only the first matching process)
$ ps -C firefox

# Show processes with high CPU usage (use top or htop for a more interactive view)
$ ps -eo pid,%cpu --sort=-%cpu | head -5

Process Status Codes:

The STAT column in the full format output displays a single-character code indicating the process status. Here are some common codes:

Further Exploration:

The ps command offers a wide range of options for filtering and formatting its output. Refer to the man ps command in your terminal for a complete list of options and their descriptions. Tools like top and htop provide a more interactive and visually appealing way to monitor processes in real-time.