Important Points About the ps Command in Linux with Examples

Process status (PS)

PS helps to display all the running process in the Linux system.

Important Points About the ps Command in Linux with Examples

The ps (Process Status) command is used to display information about active processes in Linux. It provides details like process ID (PID), user information, CPU usage, memory usage, and the command running the process. Below are the key points and examples:


1. Display Basic Information

The simplest form of the ps command shows processes associated with the current terminal session.

ps

Output Example:

PID TTY          TIME CMD
1234 pts/0    00:00:00 bash
5678 pts/0    00:00:00 ps
  • PID: Process ID.

  • TTY: Terminal associated with the process.

  • TIME: CPU time used.

  • CMD: Command that initiated the process.


2. View All Processes

To view all processes running on the system:

ps -e

or

ps -A

Output Example:

PID TTY          TIME CMD
1   ?        00:00:02 systemd
2   ?        00:00:00 kthreadd
  • ? indicates the process is not associated with any terminal.

3. Display Processes Hierarchically

To display processes in a tree format:

ps -ejH

or

ps -axjf

Output Example:

PPID   PID  PGID   SID TTY      CMD
1       10    10    10 ?        /sbin/init
10      100  100   100 ?        /usr/lib/systemd/systemd-journald
  • PPID: Parent Process ID.

  • Helps identify parent-child relationships between processes.


4. Show Detailed Process Information

To display more detailed information about processes:

ps aux

Output Example:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1  16452  1128 ?        Ss   10:00   0:00 /sbin/init
user       5678  0.3  0.3  48256  3568 pts/0   R+   10:05   0:01 ps aux
  • %CPU: CPU usage.

  • %MEM: Memory usage.

  • VSZ: Virtual memory size.

  • RSS: Resident Set Size (memory used).

  • STAT: Process state (e.g., R for running, S for sleeping).


5. Filter Processes by User

To list processes owned by a specific user:

ps -u <username>

Example:

ps -u root

6. Filter by Process Name

To search for a specific process by name:

ps -C <process_name>

Example:

ps -C sshd

Output Example:

PID TTY          TIME CMD
1224 ?        00:00:00 sshd

7. View Processes by PID

To display details of a specific process by PID:

ps -p <PID>

Example:

ps -p 1234

8. Combine ps with grep

To search for a process using a keyword:

ps aux | grep <keyword>

Example:

ps aux | grep nginx

9. Display Process CPU and Memory Usage

To sort and monitor processes consuming the most CPU or memory:

ps aux --sort=-%cpu

or

ps aux --sort=-%mem

10. Display Processes in Real-Time

While ps is static, you can use it with the watch command for real-time updates:

watch ps aux

Key Takeaways:

  • The ps command is highly versatile for process monitoring.

  • Combine with other tools like grep, watch, or top for advanced use.

  • Options like aux, -e, and -C help filter and analyze processes effectively.

0
Subscribe to my newsletter

Read articles from Amit singh deora directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Amit singh deora
Amit singh deora

DevOps | Cloud Practitioner | AWS | GIT | Kubernetes | Terraform | ArgoCD | Gitlab