Operations 8 min read

Master Linux Process Management with the ps Command: Tips & Examples

This guide explains the Linux ps command’s syntax, common options, and advanced usage—showing how to list processes, filter by state, view resource usage, display process trees, sort by CPU or memory, monitor in real time, and combine with kill or pkill to manage processes effectively.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Process Management with the ps Command: Tips & Examples

Introduction

The ps command is a fundamental Linux utility for inspecting running processes, their states, and resource consumption. It is essential for system administrators and developers who need to understand and manage the processes on a host.

Basic Usage

The basic syntax is: ps [options] Running ps without options lists the processes owned by the current user.

Process States

ps

can display the state of each process. Common state codes are: R: Running S: Sleeping Z: Zombie D: Uninterruptible sleep T: Stopped

Example – show only running processes:

ps aux | grep 'R'

Viewing a Specific User’s Processes

Use the -u option followed by a username:

ps -u username

Displaying the Full Process Tree

The ps auxf command prints a hierarchical view of parent and child processes.

ps auxf

Resource Usage

To list processes sorted by CPU usage, showing the top ten: ps aux | sort -nrk 3,3 | head -n 10 Similarly, sorting by memory:

ps aux --sort=-%mem

Detailed Information for a Specific Process

The -p option selects a PID and the -o format specifier chooses which fields to display:

ps -p PID -o pid,ppid,cmd,%cpu,%mem

Real‑Time Monitoring

Combine ps with watch to refresh the view every second:

watch -n 1 "ps aux | grep 'process_name'"

Terminating Processes

Find a process and kill it with kill -9 PID:

ps aux | grep 'process_name'
kill -9 PID

Sorting by CPU or Memory

Use --sort with a minus sign to order descending:

ps aux --sort=-%cpu
ps aux --sort=-%mem

Thread Information

Show threads of a process using the -eLf options:

ps -eLf | grep 'process_name'

User‑Specific Statistics

The -U option displays detailed statistics for a given user:

ps -U username u

Parent‑Child Relationships

List all processes with their parent IDs using the -f (full‑format) flag:

ps -ef

Process Tree for a Specific User

The pstree command can be limited to a user:

pstree -u username

Working Directory of a Process

Use pwdx PID to reveal the current working directory of a process:

pwdx PID

Killing All Processes of a User

The pkill -u username command terminates every process owned by the specified user.

pkill -u username

Conclusion

The ps utility provides a comprehensive view of process information, from basic listings to advanced filtering, sorting, and integration with other commands for real‑time monitoring and termination. Mastering its options enables effective system performance analysis and troubleshooting.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSystem AdministrationShell scriptingprocess monitoringps command
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.