Linux
is a multitasking, multi-user operating system, so it allows multiple processes to run simultaneously without interfering with each other. Process is one of the important basic concepts of the Linux
operating system. A process is an instance of a program that performs different tasks in the operating system. Linux
provides us with a utility called ps
to view information related to processes on the system. It is an abbreviation for process status
. The ps
command is used to list the currently running processes, their pid
, and some other information depending on different options. It reads process information from virtual files in the /proc
file system. process status
command ps
displays information about active processes, similar to the Task Manager in Windows
. Each operating system's version of ps
is slightly different, so if detailed information is needed, it is necessary to consult the operating system's wiki
.
ps [options]
The ps
command has various categories of parameters to choose from: simple|list|output|threads|misc|all
.
-A, -e
: Select all processes.-a
: Select all processes except session leaders and processes without a controlling terminal.a
: List all processes with a terminaltty
, including processes from other users, or list all processes when used with thex
option.-d
: Select all processes except session leaders.-N, --deselect
: Select all processes except those that satisfy the specified conditions.r
: Restrict the selection to only running processes.T
: Select all processes associated with this terminal.x
: List processes without controlling terminals for a pseudoterminal, just likeps
andEUID
, or list all processes when used with thea
option.
-C <command>
: Select by command name, this selects processes whose executable name is given incommand
.-G, --Group <GID>
: Select by real groupID (RGID)
or name, this selects processes with a real group name orID
in thegrplist
.-g, --group <group>
: Select by session or effective group name.-p, p, --pid <PID>
: Select by processID
.--ppid <PID>
: Select by parent processID
, this selects processes with a parent processID
from thepidlist
, in other words, it selects the child processes of those processes listed inpidlist
.-q, q, --quick-pid <PID>
: Select by processID
(quick mode).-s, --sid <session>
: Select by sessionID
.-t, t, --tty <tty>
: Select bytty (terminal)
.-u, U, --user <UID>
: Select by effective userID (EUID)
or name.-U, --User <UID>
: Select by real userID (RUID)
or name.
-F
: Extra full format.-f
: Full format listing, this option may be combined with otherUNIX
style options to add additional columns, it also causes the command arguments to be printed. When used with-L
, it will add theNLWP
thread count andLWP
threadID
columns.f, --forest
: ASCII art process hierarchy, like many trees, also called a forest.-H
: Display process hierarchy (forest).-j
: Job control format.j
:BSD
job control format.-l
: Long format, the-y
option is often useful with this.l
: DisplayBSD
long format.-M, Z
: Add a security data column forSE Linux
.-O <format>
: Preload default column list.O <format>
: Similar to-O
withBSD
features.-o, o, --format <format>
: Specify user-defined format.s
: Display signal format.u
: Display user-oriented format.v
: Display virtual memory format.X
: Display register format.-y
: Do not show flags, displayrss
instead ofaddr
, this option can only be used with-l
.--context
: Display security context format when usingSE Linux
.--headers
: Repeat the header line, printing it on each page of output.--no-headers
: Do not print the header line at all.--cols, --columns, --width <num>
: Set screen width.--rows, --lines <num>
: Set screen height.
H
: Show threads as if they were processes.-L
: Display threads, possibly withLWP
andNLWP
columns.-m, m
: Show threads after processes.-T
: Display threads, possibly withSPID
column.
-c
: Display different scheduler information for-l
option.c
: Display the actual command name.e
: Show environment after command.k, --sort
: Specify sorting order as[+|-]key[,[+|-]key[,...]]
.L
: Display format flags.n
: Show numericuid
andwchan
.S, --cumulative
: Include somedead
child process data.-y
: Do not display flags, showrss
, only used with-l
.-V, V, --version
: Display version information.-w, w
: Unlimited output width.--help <simple|list|output|threads|misc|all>
: Display help information.
Display processes for the current shell.
ps
View all running processes.
ps -e
Usually, viewing all processes can be combined with pipe and grep
to filter, for example, we can view all processes related to nginx
.
ps -e | grep nginx
View all processes except session leaders and processes not associated with a terminal.
ps -a
View all processes for the www
user.
ps -u www
View all processes for the www
group.
ps -G www
Use -f
to view the complete format list.
ps -f
View processes in a user-defined format.
ps -aN --format cmd,pid,user,ppid
Sort processes by memory usage.
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem
Display all current processes, for ease of viewing, it can be used in combination with pipe and less
command.
ps -ax | less
Use the aux
parameter, add CPU
and memory usage information to display comprehensive information.
ps -aux | less
Sort processes in descending order by CPU
usage.
ps -aux --sort -pcpu | less
Sort processes in descending order by memory usage.
ps -aux --sort -pmem | less
Sort processes based on overall memory and CPU
usage and display only the top 10
results.
ps -aux --sort -pcpu,+pmem | head -n 10
https://github.com/WindrunnerMax/EveryDay
https://www.computerhope.com/unix/ups.htm
https://www.runoob.com/linux/linux-comm-ps.html
https://www.geeksforgeeks.org/ps-command-in-linux-with-examples/