You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `ps` command is used to identify programs and processes that are running on the system and the resources they are using.
4
-
Its frequently [pipelined](<https://en.wikipedia.org/wiki/Pipeline_(Unix)>) with other commands like `grep` to search for a program/process or `less`
5
-
so that the user can analyze the output one page at a time.
3
+
The `ps` command (process status) is used to display information about running processes on a Linux system — such as their PID, memory usage, CPU time, and associated users.
6
4
7
-
Let's say you have a program like openshot which is notorious for hogging system resources when exporting a video, and you want to close it, but the GUI has become unresponsive.
5
+
It’s often **piped** with commands like `grep` to search for a specific process or `less` to scroll through large outputs.
8
6
9
-
### Example
7
+
##Why Use `ps`
10
8
11
-
1. You want to find the PID of openshot and kill it.
9
+
Imagine your system feels slow or an app becomes unresponsive — you can use `ps` to:
10
+
- Identify processes consuming high CPU/memory
11
+
- Find a program’s PID (Process ID)
12
+
- Kill or debug a stuck process
13
+
- Check who’s running what on a shared system
14
+
15
+
## Basic Syntax
16
+
17
+
```
18
+
ps [options]
19
+
```
20
+
21
+
Without any options, `ps` only shows processes in the current terminal session.
22
+
23
+
Example:
24
+
```bash
25
+
ps
26
+
```
27
+
28
+
Output:
29
+
```
30
+
PID TTY TIME CMD
31
+
4587 pts/0 00:00:00 bash
32
+
4621 pts/0 00:00:00 ps
33
+
```
34
+
35
+
## Essential Usage
36
+
37
+
**The one combo to remember:**`ps aux`
38
+
-`a` = all processes (all users)
39
+
-`u` = show user/owner info
40
+
-`x` = include processes without terminals
41
+
42
+
```
43
+
ps aux
44
+
```
45
+
46
+
Output example:
47
+
```
48
+
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
When run without any options, it's useless and will print: `CMD` - the executable processes/(program) running, their `PID` - process ID, `TTY` - terminal type and `Time` - How long the process has utilized the CPU or thread.
89
+
Show top 10 memory-consuming processes:
90
+
```
91
+
ps aux --sort=-%mem | head -10
92
+
```
93
+
94
+
Show top 10 CPU-consuming processes:
95
+
```
96
+
ps aux --sort=-%cpu | head -10
97
+
```
98
+
99
+
### Checking Parent/Child Process Hierarchy
100
+
```bash
101
+
ps -ef --forest
102
+
```
103
+
This gives a tree-like structure showing parent-child relationships — useful when debugging service spawns.
104
+
105
+
### Custom Output Format
106
+
To Show only PID, user, memory, and command:
107
+
```
108
+
ps -eo pid,user,%mem,cmd
109
+
```
110
+
111
+
## Real-Life DevOps Examples
112
+
113
+
### 1. Checking which process uses a specific port
114
+
```
115
+
sudo ps -fp $(sudo lsof -t -i:8080)
116
+
```
30
117
31
-
### Common Option
118
+
### 2. Monitoring Jenkins, Nginx, or Docker processes
119
+
```
120
+
ps aux | grep nginx
121
+
ps aux | grep jenkins
122
+
ps aux | grep docker
123
+
```
32
124
33
-
If you are going to remember only one thing from this page let it be these three letter `aux`:
34
-
`a` - which displays all processes running, including those being run by other users.
35
-
`u` - which shows the effective user of a process, i.e. the person whose file access permissions are used by the process.
36
-
`x` - which shows processes that do not have a `TTY` associated with them.
125
+
### 3. Find Zombie Processes
126
+
```
127
+
ps aux | awk '{ if ($8 == "Z") print $0; }'
128
+
```
129
+
130
+
## Key Options for Quick Reference
131
+
132
+
| Option | Description |
133
+
|:-------|:------------|
134
+
|`aux`| All processes with detailed info |
135
+
|`-ef`| Full listing (alternative to aux) |
136
+
|`-eo format`| Custom output columns |
137
+
|`--sort`| Sort by column (-%mem, -%cpu) |
138
+
|`-p PID`| Show specific PID |
139
+
|`-C name`| Show processes by command name |
140
+
|`-u user`| Show user's processes |
141
+
|`f`| ASCII art process tree |
37
142
38
143
### Additional Options:
39
144
@@ -51,4 +156,15 @@ If you are going to remember only one thing from this page let it be these three
51
156
|`--help simple`|Shows all the basic options|
52
157
|`--help all`|Shows every available options|
53
158
54
-
Another useful command which give a realtime snapshot of the processes and the resources they are using about every ten seconds is `top`.
0 commit comments