Bash ps Command - Snapshot of Current Processes
Using the ps Command
The ps command is used to report a snapshot of current processes.
It's a useful tool for monitoring and managing processes on your system.
All examples below come from the same system. The user user is running bash and a Python script in one terminal (pts/0), and a Node.js server in the background with no terminal.
Understanding the Output
The ps command output consists of several columns, each representing different aspects of the system's processes:
- PID: Process ID, a unique identifier for each process.
- TTY: Terminal type associated with the process.
- TIME: Total CPU time used by the process.
- CMD: The command that started the process.
Basic Usage
To display a snapshot of current processes, use ps:
Example: Basic Usage
ps
PID TTY TIME CMD
1234 pts/0 00:00:01 bash
5678 pts/0 00:00:02 python
9200 pts/0 00:00:00 ps
Without options, ps only shows the processes in your current terminal, including ps itself.
Options
The ps command has options to change how it works:
-e- Show all processes-f- Show detailed information-u- Show processes for a specific user-a- Show all processes with a terminal-x- Show processes without a terminal
Show All Processes
The -e option allows you to show all processes.
Example: Show All Processes
ps -e
PID TTY TIME CMD
1 ? 00:00:02 systemd
1234 pts/0 00:00:01 bash
5678 pts/0 00:00:02 python
9101 ? 00:00:03 node
9200 pts/0 00:00:00 ps
A real system has many more processes. A ? in the TTY column means the process has no terminal.
Show Detailed Information
The -f option allows you to show detailed information.
Example: Show Detailed Information
ps -f
UID PID PPID C STIME TTY TIME CMD
user 1234 1100 0 08:00 pts/0 00:00:01 bash
user 5678 1234 0 08:01 pts/0 00:00:02 python app.py
user 9200 1234 0 08:05 pts/0 00:00:00 ps -f
Show Processes for a Specific User
The -u option allows you to show processes for a specific user.
Example: Show Processes for a Specific User
ps -u user
PID TTY TIME CMD
1234 pts/0 00:00:01 bash
5678 pts/0 00:00:02 python
9101 ? 00:00:03 node
9200 pts/0 00:00:00 ps
Show Processes with a Terminal
The -a option allows you to show all processes with a terminal.
Example: Show Processes with a Terminal
ps -a
PID TTY TIME CMD
5678 pts/0 00:00:02 python
9200 pts/0 00:00:00 ps
The shell (bash) is not listed, because -a leaves out session leaders.
Show Processes without a Terminal
The -x option allows you to show processes without a terminal.
Example: Show Processes without a Terminal
ps -x
PID TTY STAT TIME COMMAND
1234 pts/0 Ss 0:01 bash
5678 pts/0 S+ 0:02 python app.py
9101 ? Ssl 0:03 node server.js
9200 pts/0 R+ 0:00 ps -x
It lists your own processes, including the ones without a terminal (like node here). It also uses a different output format, with a STAT column for the process state.
Combining Options
Options can be combined to provide more detailed output. For example, ps -ef shows all processes with detailed information.
Example: Combine Options
ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 07:58 ? 00:00:02 /sbin/init
user 1234 1100 0 08:00 pts/0 00:00:01 bash
user 5678 1234 0 08:01 pts/0 00:00:02 python app.py
user 9101 1 0 08:02 ? 00:00:03 node server.js
user 9200 1234 0 08:05 pts/0 00:00:00 ps -ef