ps Command in Linux/Unix with Examples
The ps
command in Linux is used to view currently running processes on the system. It provides detailed information about processes, including their process ID (PID), resource usage, user ID, command name, and more.
Introduction to PS Command
The ps
command shows details of running processes, and it can be used with various options to customize the output. It helps in monitoring system activities, resource utilization, and identifying specific processes.
Syntax:
ps [options]
Example:
$ ps
Output
The output includes columns such as PID (Process ID), %CPU (CPU usage), %MEM (Memory usage), ADDR (Memory address), COMMAND (Command name), USER (Username), TTY (Terminal), TIME (CPU time), and more.
Options:
ps -ef
or ps -aux
: List currently running processes in full format.
$ ps -ef
ps -ax
: List all currently running processes.
$ ps -ax
ps -u <username>
: List processes for a specific user.
$ ps -u john
ps -C <command>
: List processes for a given command.
$ ps -C apache2
ps -p <PID>
: List processes with a given Process ID.
$ ps -p 1234
ps -ppid <PPID>
: List processes with a given Parent Process ID.
$ ps -ppid 5678
pstree
: Show processes in the hierarchy.
$ pstree
ps -L
: List all threads for a particular process.
$ ps -L 5678
ps --sort pmem
: Find memory usage and sort by memory.
$ ps --sort pmem
ps -eo
: Show security information.
$ ps -eo pid,user,cmd
ps -U root -u root u
: Show processes running as root.
$ ps -U root -u root u
Linux ps -ef and ps -aux: To display all currently running processes in full format, two common commands are used:
ps -ef
ps -aux
Example:
$ ps -ef
This command provides a detailed list of all running processes, including information about CPU and memory usage.
Linux ps -ax: The ps -ax
command lists all currently running processes on the system.
Example:
$ ps -ax
This command displays a long list of processes, providing information such as PID, TTY, TIME, and CMD.
These examples demonstrate how the ps
command can be used to gather information about processes, identify resource usage, and monitor system activities.