Skip to content
Search

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

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

Favorite site

References


  1. BASH_shell-script.pdf ↩

author Zer0 sitemap