Ps
lastmod 2023-04-10created 2014-03-0124 edits
ps (Processor Status) is a command that shows the status of currently running processes.
Process State Codes
- [Recommended] Bash shell script guide — mug896 - Process State Codes 1
Commandline options
Commonly used options are listed below.
-
-e: Show all processes. -
-f: Show processes with full paths. -
-l: Output in long format. -
-u: Show the user who ran it and the run time. -
-j: Show in "job" format. -
-s: Show in signal format. -
-m: Show memory information. -
-a: Show the processes of other users. -
-x: Show processes without a controlling terminal. -
-w: Show detailed descriptions of processes. -
-o: User-defined format.
Reading the output
The kinds of information shown and their meanings are as follows.
-
PID: Process ID -
TTY: Terminal port associated with the process -
TIME: CPU time used by the process -
CMD: Command
The following information appears when the -u option is used.
-
USER: Process user -
%CPU: CPU usage percentage -
%MEM: Memory usage percentage -
VSZ: Virtual memory usage -
RSS: Physical memory usage -
STAT: Current process state-
R: Running or runnable -
S: Sleeping -
I: Idle -
T: Stopped -
Z: Zombie process -
W: Swapped out -
P: Waiting for a page -
D: Waiting for disk -
N: Priority lowered with nice
-
START: Time or date the process started The following information appears when the -l option is used.
-
F: Flags associated with the process -
S: Process state (same as the STAT field above) -
PPID: PID of the parent process -
C: Short-term CPU usage -
PRI: Actual scheduling priority -
NI: nice value of the process -
WCHAN: Event the process is waiting for
Example
-
ps -ef | grep httpd - Finds httpd (Apache HTTPD) with the e (show all processes) and f (include full paths) options.
-
ps -eo state,uid,pid,ppid,rtprio,time,comm - Output in a user-defined format. Note that RTPRIO is the real-time priority, ranging from 0 to 99. '-' means the process is not a real-time process.
-
ps elf - Shows all processes, including full paths, in long format.
-
ps aux - Shows the user who ran each process and the run time, shows the processes of other users, and shows processes without a controlling terminal.
=== Memory usage == Ways to check the Resident set size (RSS; the amount of physical memory actually occupied)
- Quick check
-
ps -ef --sort -rss
- Memory usage of the top 10 processes
-
ps -ef --sort -rss | head -n 11
- Show memory usage
-
ps -eo user,pid,ppid,rss,size,vsize,pmem,pcpu,time,cmd --sort -rss | head -n 11
- Hide the arguments of the process command
-
ps -eo user,pid,ppid,rss,size,vsize,pmem,pcpu,time,comm --sort -rss | head -n 11
How to calculate usage:
- Nominal memory usage:
used / total = ( total - free ) / total - Effective memory usage:
used2 / total = ( total - free2 ) / total = ( total - free - buffers - cached) / total
See also
- top
- htop
- ctop
- Resource usage
- eDEX-UI
- bashtop
- procs - replacement for ps written in Rust.
- kill - Sends a signal to a specific process by process ID.
- skill - Sends a signal to specific processes by USER name.
- pkill - Sends a signal to specific processes by process name.
- Cache
- ProcMon-for-Linux - A Linux reimagining of the classic Procmon tool from the Sysinternals suite of tools for Windows.
- magic-trace
- Sampler - A tool for running, visualizing, and alerting on shell commands
Favorite site
- ps / kill, pkill, skill commands
- Analyzing memory usage per process
- Stackoverflow - Viewing full output of PS command
- Notes on the Linux PS command
- ps - Linux Command
- How to use the Linux ps command
References
-
BASH_shell-script.pdf ↩