1.\" $NetBSD: ps.1,v 1.115 2021/11/06 06:38:03 msaitoh Exp $ 2.\" 3.\" Copyright (c) 1980, 1990, 1991, 1993, 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)ps.1 8.3 (Berkeley) 4/18/94 31.\" 32.Dd November 6, 2021 33.Dt PS 1 34.Os 35.Sh NAME 36.Nm ps 37.Nd process status 38.Sh SYNOPSIS 39.Nm 40.Op Fl AaCcdehjlmrSsTuvwx 41.Op Fl G Ar group 42.Op Fl k Ar key 43.Op Fl M Ar core 44.Op Fl N Ar system 45.Op Fl O Ar fmt 46.Op Fl o Ar fmt 47.Op Fl p Ar pid 48.Op Fl t Ar tty 49.Op Fl U Ar user 50.Op Fl W Ar swap 51.Nm 52.Fl L 53.Sh DESCRIPTION 54.Nm 55displays a header line followed by lines containing information about 56running processes. 57By default, the display includes only processes that have 58controlling terminals and are owned by your uid. 59The default sort order of controlling terminal and 60(among processes with the same controlling terminal) process ID 61may be changed using the 62.Fl k , Fl m , 63or 64.Fl r 65options. 66.Pp 67The information displayed for each process 68is selected based on a set of keywords (see the 69.Fl L , 70.Fl O , 71and 72.Fl o 73options). 74The default output format includes, for each process, the process' ID, 75controlling terminal, CPU time (including both user and system time), 76state, and associated command. 77.Pp 78The options are as follows: 79.Bl -tag -width XNXsystemXX 80.It Fl A 81Display information about all processes. 82This is equivalent to 83.Fl a Fl x . 84.It Fl a 85Display information about other users' processes as well as your own. 86Note that this does not display information about processes 87without controlling terminals. 88.It Fl C 89Change the way the CPU percentage is calculated by using a 90.Dq raw 91CPU calculation that ignores 92.Dq resident 93time (this normally has no effect). 94.It Fl c 95Do not display full command with arguments, but only the 96executable name. 97This may be somewhat confusing; for example, all 98.Xr sh 1 99scripts will show as 100.Dq sh . 101.It Fl d 102Arrange processes into descendancy order and prefix each command with 103indentation text showing sibling and parent/child relationships. 104If either of the 105.Fl m 106and 107.Fl r 108options are also used, they control how sibling processes are sorted 109relative to each other. 110.It Fl e 111Display the environment as well. 112The environment for other 113users' processes can only be displayed by the super-user. 114.It Fl G Ar group 115Display processes belonging to the users belonging to the specified group, 116given either as a group name or a gid. 117.It Fl h 118Repeat the information header as often as necessary to guarantee one 119header per page of information. 120.It Fl j 121Print information associated with the following keywords: 122.Ar user , pid , ppid , pgid , sess , jobc , state , tt , time , 123and 124.Ar command . 125.It Fl k Ar key 126Sort the output using the space or comma separated list of keywords. 127Multiple sort keys may be specified, using any of the 128.Fl k , Fl m , 129or 130.Fl r 131options. 132The default sort order is equivalent to 133.Fl k Ar tdev,pid . 134.It Fl L 135List the set of available keywords. 136.It Fl l 137Display information associated with the following keywords: 138.Ar uid , pid , ppid , cpu , pri , nice , vsz , rss , wchan , state , 139.Ar tt , time , 140and 141.Ar command . 142.It Fl M Ar core 143Extract values from the specified core file instead of the running system. 144.It Fl m 145Sort by memory usage. 146This is equivalent to 147.Fl k Ar vsz . 148.It Fl N Ar system 149Extract the name list from the specified system instead of the default, 150.Dq Pa /netbsd . 151Ignored unless 152.Fl M 153is specified. 154.It Fl O Ar fmt 155Display information associated with the space or comma separated list 156of keywords specified. 157The 158.Fl O 159option does not suppress the default display; 160it inserts additional keywords just after the 161.Ar pid 162keyword in the default display, or after the 163.Ar pid 164keyword (if any) in a non-default display specified before the 165first use of the 166.Fl O 167flag. 168Keywords inserted by multiple 169.Fl O 170options will be adjacent. 171.Pp 172An equals sign 173.Pq Dq \&= 174followed by a customised header string may be appended to a keyword, 175as described in more detail under the 176.Fl o 177option. 178.It Fl o Ar fmt 179Display information associated with the space or comma separated list 180of keywords specified. 181Use of the 182.Fl o 183option suppresses the set of keywords that would be displayed by default, 184or appends to the set of keywords specified by other options. 185.Pp 186An equals sign 187.Pq Dq \&= 188followed by a customised header string may be appended to a keyword. 189This causes the printed header to use the specified string instead of 190the default header associated with the keyword. 191.Pp 192Everything after the first equals sign is part of the customised 193header text, and this may include embedded spaces 194.Pq Dq " " , 195commas 196.Pq Dq \&, , 197or equals signs 198.Pq Dq \&= . 199To specify multiple keywords with customised headers, use multiple 200.Fl o 201or 202.Fl O 203options. 204.Pp 205If all the keywords to be displayed have customised headers, 206and all the customised headers are entirely empty, 207then the header line is not printed at all. 208.Pp 209If the keyword is capitalized, then an alternate (symbolic) form of it 210is printed, if available. 211.It Fl p Ar pid 212Display information associated with the specified process ID. 213.It Fl r 214Sort by current CPU usage. 215This is equivalent to 216.Fl k Ar %cpu . 217.It Fl S 218Change the way the process time is calculated by summing all exited 219children to their parent process. 220.It Fl s 221Display one line for each LWP, rather than one line for each process, 222and display information associated with the following keywords: 223.Ar uid , pid , ppid , cpu , lid , nlwp , pri , nice , vsz , rss , 224.Ar wchan , lstate , tt , time , 225and 226.Ar command . 227.It Fl T 228Display information about processes attached to the device associated 229with the standard input. 230.It Fl t Ar tty 231Display information about processes attached to the specified terminal 232device. 233Use a question mark 234.Pq Dq \&? 235for processes not attached to a 236terminal device and a minus sign 237.Pq Dq - 238for processes that have 239been revoked from their terminal device. 240.It Fl U Ar user 241Display processes belonging to the specified user, 242given either as a user name or a uid. 243.It Fl u 244Display information associated with the following keywords: 245.Ar user , pid , %cpu , %mem , vsz , rss , tt , state , start , time , 246and 247.Ar command . 248The 249.Fl u 250option implies the 251.Fl r 252option. 253.It Fl v 254Display information associated with the following keywords: 255.Ar pid , state , time , sl , re , pagein , vsz , rss , lim , tsiz , 256.Ar %cpu , %mem , 257and 258.Ar command . 259The 260.Fl v 261option implies the 262.Fl m 263option. 264.It Fl W Ar swap 265Extract swap information from the specified file instead of the default, 266.Dq Pa /dev/drum . 267Ignored unless 268.Fl M 269is specified. 270.It Fl w 271Use 132 columns to display information instead of the default, which 272is your window size. 273If the 274.Fl w 275option is specified more than once, 276.Nm 277will use as many columns as necessary without regard to your window size. 278.It Fl x 279Also display information about processes without controlling terminals. 280.El 281.Pp 282A complete list of the available keywords are listed below. 283Some of these keywords are further specified as follows: 284.Bl -tag -width indent 285.It Ar %cpu 286The CPU utilization of the process; this is a decaying average over up to 287a minute of previous (real) time. 288Since the time base over which this is computed varies (since processes may 289be very young) it is possible for the sum of all %CPU fields to exceed 100%. 290.It Ar %mem 291The percentage of real memory used by this process. 292.It Ar flags 293The flags (in hexadecimal) associated with the process as in 294the include file 295.In sys/sysctl.h : 296.Bl -column P_NOCLDSTOP P_NOCLDSTOP compact 297.It Dv "P_ADVLOCK" Ta No "0x00000001 process may hold a POSIX advisory lock" 298.It Dv "P_CONTROLT" Ta No "0x00000002 process has a controlling terminal" 299.It Dv "P_INMEM" Ta No "0x00000004 process is in memory" 300.It Dv "P_NOCLDSTOP" Ta No "0x00000008 no" Dv SIGCHLD No when children stop 301.It Dv "P_PPWAIT" Ta No "0x00000010 parent is waiting for child to exec/exit" 302.It Dv "P_PROFIL" Ta No "0x00000020 process has started profiling" 303.It Dv "P_SELECT" Ta No "0x00000040 selecting; wakeup/waiting danger" 304.It Dv "P_SINTR" Ta No "0x00000080 sleep is interruptible" 305.It Dv "P_SUGID" Ta No "0x00000100 process had set id privileges since last exec" 306.It Dv "P_SYSTEM" Ta No "0x00000200 system process: no sigs or stats" 307.It Dv "P_SA" Ta No "0x00000400 process is using scheduler activations (old)" 308.It Dv "P_TRACED" Ta No "0x00000800 process is being traced" 309.It Dv "P_WAITED" Ta No "0x00001000 debugging process has waited for child" 310.It Dv "P_WEXIT" Ta No "0x00002000 working on exiting" 311.It Dv "P_EXEC" Ta No "0x00004000 process called" Xr execve 2 312.It Dv "P_OWEUPC" Ta No "0x00008000 owe process an addupc() call at next ast" 313.It Dv "P_NOCLDWAIT" Ta No "0x00020000 no zombies if child dies" 314.It Dv "P_32" Ta No "0x00040000 32-bit process (used on 64-bit kernels)" 315.It Dv "P_CLDSIGIGN" Ta No "0x0008000 no" Dv SIGCHLD when children stop 316.It Dv "P_SYSTRACE" Ta No "0x00200000 process is under" Xr systrace 1 (old) 317.It Dv "P_CHTRACED" Ta No "0x00400000 process has been traced and reparented" 318.It Dv "P_STOPFORK" Ta No "0x00800000 process stops at" Xr fork 2 319.It Dv "P_STOPEXEC" Ta No "0x01000000 process stops at" Xr exec 2 320.It Dv "P_STOPEXIT" Ta No "0x02000000 process stops at" Xr _exit 2" 321.It Dv "P_SYSCALL" Ta No "0x04000000 process is tracing syscalls" 322.El 323.It Ar lim 324The soft limit on memory used, specified via a call to 325.Xr setrlimit 2 . 326.It Ar lstart 327The exact time the command started, using the 328.Dq \&%c 329format described in 330.Xr strftime 3 . 331.It Ar maxrss 332the maximum resident set size of the process (in 1024 byte units). 333.It Ar nice 334The process scheduling increment (see 335.Xr setpriority 2 ) . 336.It Ar rss 337the real memory (resident set) size of the process (in 1024 byte units). 338.It Ar start 339The time the command started. 340If the command started less than 24 hours ago, the start time is 341displayed using the 342.Dq %l:%M%p 343format described in 344.Xr strftime 3 . 345If the command started less than 7 days ago, the start time is 346displayed using the 347.Dq %a%p 348format. 349Otherwise, the start time is displayed using the 350.Dq %e%b%y 351format. 352.It Ar state 353The state is given by a sequence of letters, for example, 354.Dq RNs . 355The first letter indicates the run state of the process: 356.Pp 357.Bl -tag -width indent -compact 358.It D 359Marks a process in device or other short term, uninterruptible wait. 360.It I 361Marks a process that is idle (sleeping interruptibly for longer than about 362.Dv MAXSLP 363(default 20) seconds). 364.It O 365Marks a process running on a processor. 366.It R 367Marks a runnable process, or one that is in the process of creation. 368.It S 369Marks a process that is sleeping interruptibly for less than about 370.Dv MAXSLP 371(default 20) seconds. 372.It T 373Marks a stopped process. 374.It U 375Marks a suspended process. 376.It Z 377Marks a dead process that has exited, but not been waited for (a 378.Dq zombie ) . 379.El 380.Pp 381Additional characters after these, if any, indicate additional state 382information: 383.Pp 384.Bl -tag -width indent -compact 385.It + 386The process is in the foreground process group of its control terminal. 387.It - 388The LWP is detached (can't be waited for). 389.It < 390The process has raised CPU scheduling priority. 391.It a 392The process is using scheduler activations (deprecated). 393.It E 394The process is in the process of exiting. 395.It K 396The process is a kernel thread or system process. 397.It l 398The process has multiple LWPs. 399.It N 400The process is niced (has reduced CPU scheduling priority) (see 401.Xr setpriority 2 ) . 402.It s 403The process is a session leader. 404.It V 405The process is suspended during a 406.Xr vfork 2 . 407.It X 408The process is being traced or debugged. 409.El 410.It Ar tt 411An abbreviation for the pathname of the controlling terminal, if any. 412The abbreviation consists of the two letters following 413.Dq Pa /dev/tty 414or, for the console, 415.Dq co . 416This is followed by a 417.Dq \&- 418if the process can no longer reach that 419controlling terminal (i.e., it has been revoked). 420.It Ar wchan 421The event (an address in the system) on which a process waits. 422When printed numerically, the initial part of the address is 423trimmed off and the result is printed in hex, for example, 0x80324000 prints 424as 324000. 425.El 426.Pp 427When printing using the 428.Ar command 429keyword, a process that has exited and has a parent that has not yet 430waited for the process (in other words, a zombie) is listed as 431.Dq Aq defunct , 432and a process which is blocked while trying to exit is listed as 433.Dq Aq exiting . 434.Pp 435.Nm 436will try to locate the processes' argument vector from the user 437area in order to print the command name and arguments. 438This method is not reliable because a process is allowed to destroy this 439information. 440The 441.Ar ucomm 442(accounting) keyword will always contain the real command name as 443contained in the process structure's 444.Va p_comm 445field. 446.Pp 447If the command vector cannot be located (usually because it has not 448been set, as is the case of system processes and/or kernel threads) 449the command name is printed within square brackets. 450.Pp 451To indicate that the argument vector has been tampered with, 452.Nm 453will append the real command name to the output within parentheses 454if the basename of the first argument in the argument vector 455does not match the contents of the real command name. 456.Pp 457In addition, 458.Nm 459checks for the following two situations and does not append the 460real command name parenthesized: 461.Bl -tag -width indent 462.It -shellname 463The login process traditionally adds a 464.Sq - 465in front of the shell name to indicate a login shell. 466.Nm 467will not append parenthesized the command name if it matches with 468the name in the first argument of the argument vector, skipping 469the leading 470.Sq - . 471.It daemonname: current-activity 472Daemon processes frequently report their current activity by setting 473their name to be like 474.Dq daemonname: current-activity . 475.Nm 476will not append parenthesized the command name, if the string preceding the 477.Sq \&: 478in the first argument of the argument vector matches the command name. 479.El 480.Sh KEYWORDS 481The following is a complete list of the available keywords and their 482meanings. 483Several of them have aliases (keywords which are synonyms). 484.Pp 485.Bl -tag -width groupnames -compact 486.It Ar %cpu 487percentage CPU usage (alias 488.Ar pcpu ) 489.It Ar %mem 490percentage memory usage (alias 491.Ar pmem ) 492.It Ar acflag 493accounting flag (alias 494.Ar acflg ) 495.It Ar comm 496command (the argv[0] value) 497.It Ar command 498command and arguments (alias 499.Ar args ) 500.It Ar cpu 501short-term CPU usage factor (for scheduling) 502.It Ar cpuid 503CPU number the current process or lwp is running on. 504.It Ar ctime 505accumulated CPU time of all children that have exited 506.It Ar egid 507effective group id 508.It Ar egroup 509group name (from egid) 510.It Ar emul 511emulation name 512.It Ar etime 513elapsed time since the process was started, in the form 514.Li [[dd-]hh:]mm:ss 515.It Ar euid 516effective user id 517.It Ar euser 518user name (from euid) 519.It Ar flags 520the process flags, in hexadecimal (alias 521.Ar f ) 522.It Ar gid 523effective group id 524.It Ar group 525group name (from gid) 526.It Ar groupnames 527group names (from group access list) 528.It Ar groups 529group access list 530.It Ar idrss 531integral unshared data 532.It Ar isrss 533integral unshared stack 534.It Ar ixrss 535integral shared memory size 536.It Ar inblk 537total blocks read (alias 538.Ar inblock ) 539.It Ar jobc 540job control count 541.It Ar ktrace 542tracing flags 543.It Ar ktracep 544tracing vnode 545.It Ar laddr 546kernel virtual address of the 547.Ft "struct lwp" 548belonging to the LWP. 549.It Ar lid 550ID of the LWP 551.It Ar lim 552memory use limit 553.It Ar lname 554descriptive name of the LWP 555.It Ar logname 556login name of user who started the process (alias 557.Ar login ) 558.It Ar lstart 559time started 560.It Ar lstate 561symbolic LWP state 562.It Ar ltime 563CPU time of the LWP 564.It Ar majflt 565total page faults 566.It Ar maxrss 567maximum resident set size 568.It Ar minflt 569total page reclaims 570.It Ar msgrcv 571total messages received (reads from pipes/sockets) 572.It Ar msgsnd 573total messages sent (writes on pipes/sockets) 574.It Ar nice 575nice value (alias 576.Ar ni ) 577.It Ar nivcsw 578total involuntary context switches 579.It Ar nlwp 580number of LWPs in the process 581.It Ar nsigs 582total signals taken (alias 583.Ar nsignals ) 584.It Ar nvcsw 585total voluntary context switches 586.It Ar nwchan 587wait channel (as an address) 588.It Ar oublk 589total blocks written (alias 590.Ar oublock ) 591.It Ar p_ru 592resource usage pointer (valid only for zombie) 593.It Ar paddr 594kernel virtual address of the 595.Ft "struct proc" 596belonging to the process. 597.It Ar pagein 598pageins (same as majflt) 599.It Ar pgid 600process group number 601.It Ar pid 602process ID 603.It Ar ppid 604parent process ID 605.It Ar pri 606scheduling priority 607.It Ar re 608core residency time (in seconds; 127 = infinity) 609.It Ar rgid 610real group ID 611.It Ar rlink 612reverse link on run queue, or 0 613.It Ar rlwp 614number of LWPs on a processor or run queue 615.It Ar rss 616resident set size 617.It Ar rsz 618resident set size + (text size / text use count) (alias 619.Ar rssize ) 620.It Ar ruid 621real user ID 622.It Ar ruser 623user name (from ruid) 624.It Ar sess 625session pointer 626.It Ar sid 627session ID 628.It Ar sig 629pending signals (alias 630.Ar pending ) 631.It Ar sigcatch 632caught signals (alias 633.Ar caught ) 634.It Ar sigignore 635ignored signals (alias 636.Ar ignored ) 637.It Ar sigmask 638blocked signals (alias 639.Ar blocked ) 640.It Ar sl 641sleep time (in seconds; 127 = infinity) 642.It Ar start 643time started 644.It Ar state 645symbolic process state (alias 646.Ar stat ) 647.It Ar stime 648accumulated system CPU time 649.It Ar svgid 650saved gid from a setgid executable 651.It Ar svgroup 652group name (from svgid) 653.It Ar svuid 654saved uid from a setuid executable 655.It Ar svuser 656user name (from svuid) 657.It Ar tdev 658control terminal device number 659.It Ar time 660accumulated CPU time, user + system (alias 661.Ar cputime ) 662.It Ar tpgid 663control terminal process group ID 664.It Ar tsess 665control terminal session pointer 666.It Ar tsiz 667text size (in Kbytes) 668.It Ar tt 669control terminal name (two letter abbreviation) 670.It Ar tty 671full name of control terminal 672.It Ar uaddr 673kernel virtual address of the 674.Ft "struct user" 675belonging to the LWP. 676.It Ar ucomm 677name to be used for accounting 678.It Ar uid 679effective user ID 680.It Ar upr 681scheduling priority on return from system call (alias 682.Ar usrpri ) 683.It Ar user 684user name (from uid) 685.It Ar utime 686accumulated user CPU time 687.It Ar vsz 688virtual size in Kbytes (alias 689.Ar vsize ) 690.It Ar wchan 691wait channel (as a symbolic name) 692.It Ar xstat 693exit or stop status (valid only for stopped or zombie process) 694.El 695.Sh FILES 696.Bl -tag -width /var/run/kvm.db -compact 697.It Pa /dev 698special files and device names 699.It Pa /dev/drum 700default swap device 701.It Pa /var/run/dev.cdb 702/dev name database 703.It Pa /var/db/kvm.db 704system name list database 705.It Pa /netbsd 706default system name list 707.El 708.Sh SEE ALSO 709.Xr kill 1 , 710.Xr pgrep 1 , 711.Xr pkill 1 , 712.Xr sh 1 , 713.Xr w 1 , 714.Xr kvm 3 , 715.Xr strftime 3 , 716.Xr dev_mkdb 8 , 717.Xr pstat 8 718.Sh HISTORY 719A 720.Nm 721utility appeared in 722.At v3 723in section 8 of the manual. 724.Sh BUGS 725Since 726.Nm 727cannot run faster than the system and is run as any other scheduled 728process, the information it displays can never be exact. 729.Pp 730The 731.Fl G 732option should ideally take a list instead of a single group. 733