xref: /netbsd/bin/ps/ps.1 (revision bf9ec67e)
1.\"	$NetBSD: ps.1,v 1.51 2002/04/24 08:58:33 wiz 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. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.\"     @(#)ps.1	8.3 (Berkeley) 4/18/94
35.\"
36.Dd April 18, 1994
37.Dt PS 1
38.Os
39.Sh NAME
40.Nm ps
41.Nd process status
42.Sh SYNOPSIS
43.Nm ""
44.Op Fl acCehjKlmrSTuvwx
45.Bk -words
46.Op Fl M Ar core
47.Ek
48.Bk -words
49.Op Fl N Ar system
50.Ek
51.Bk -words
52.Op Fl O Ar fmt
53.Ek
54.Bk -words
55.Op Fl o Ar fmt
56.Ek
57.Bk -words
58.Op Fl p Ar pid
59.Ek
60.Bk -words
61.Op Fl t Ar tty
62.Ek
63.Bk -words
64.Op Fl U Ar username
65.Ek
66.Bk -words
67.Op Fl W Ar swap
68.Ek
69.Nm ""
70.Op Fl L
71.Sh DESCRIPTION
72.Nm
73displays a header line followed by lines containing information about your
74processes that have controlling terminals.
75This information is sorted by controlling terminal and (among processes with
76the same controlling terminal) by process
77.Tn ID .
78.Pp
79The information displayed is selected based on a set of keywords (see the
80.Fl L
81.Fl O
82and
83.Fl o
84options).
85The default output format includes, for each process, the process'
86.Tn ID ,
87controlling terminal, cpu time (including both user and system time),
88state, and associated command.
89.Pp
90The options are as follows:
91.Bl -tag -width indent
92.It Fl a
93Display information about other users' processes as well as your own.
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 C
102Change the way the cpu percentage is calculated by using a ``raw''
103cpu calculation that ignores ``resident'' time (this normally has
104no effect).
105.It Fl e
106Display the environment as well.  The environment for other
107users' processes can only be displayed by the super-user.
108.It Fl h
109Repeat the information header as often as necessary to guarantee one
110header per page of information.
111.It Fl j
112Print information associated with the following keywords:
113user, pid, ppid, pgid, sess, jobc, state, tt, time, and command.
114.It Fl K
115Disable the fallback /proc-based method.  Note that the /proc-based method
116is only used if the ordinary kvm method is not possible.  See below for more
117details.
118.It Fl L
119List the set of available keywords.
120.It Fl l
121Display information associated with the following keywords:
122uid, pid, ppid, cpu, pri, nice, vsz, rss, wchan, state, tt, time,
123and command.
124.It Fl M
125Extract values associated with the name list from the specified core
126instead of the default
127.Dq Pa /dev/kmem .
128The
129.Fl M
130option implies the
131.Fl K
132option.
133.It Fl m
134Sort by memory usage, instead of by process
135.Tn ID .
136.It Fl N
137Extract the name list from the specified system instead of the default
138.Dq Pa /netbsd .
139.It Fl O
140Add the information associated with the space or comma separated list
141of keywords specified, after the process
142.Tn ID ,
143in the default information
144display.
145Keywords may be appended with an equals (``='') sign and a string.
146This causes the printed header to use the specified string instead of
147the standard header.
148.It Fl o
149Display information associated with the space or comma separated list
150of keywords specified.
151Keywords may be appended with an equals (``='') sign and a string.
152This causes the printed header to use the specified string instead of
153the standard header.
154.It Fl p
155Display information associated with the specified process
156.Tn ID .
157.It Fl r
158Sort by current cpu usage, instead of by process
159.Tn ID .
160.It Fl S
161Change the way the process time is calculated by summing all exited
162children to their parent process.
163.It Fl T
164Display information about processes attached to the device associated
165with the standard input.
166.It Fl t
167Display information about processes attached to the specified terminal
168device.  Use an question mark (``?'') for processes not attached to a
169terminal device and a minus sign (``-'') for processes that have
170been revoked from their terminal device.
171.It Fl U
172Displays processes belonging to the user whose username or uid has
173been given to the
174.Fl U
175switch.
176.It Fl u
177Display information associated with the following keywords:
178user, pid, %cpu, %mem, vsz, rss, tt, state, start, time, and command.
179The
180.Fl u
181option implies the
182.Fl r
183option.
184.It Fl v
185Display information associated with the following keywords:
186pid, state, time, sl, re, pagein, vsz, rss, lim, tsiz,
187%cpu, %mem, and command.
188The
189.Fl v
190option implies the
191.Fl m
192option.
193.It Fl W
194Extract swap information from the specified file instead of the
195default
196.Dq Pa /dev/drum .
197.It Fl w
198Use 132 columns to display information, instead of the default which
199is your window size.
200If the
201.Fl w
202option is specified more than once,
203.Nm
204will use as many columns as necessary without regard for your window size.
205.It Fl x
206Also display information about processes without controlling terminals.
207.El
208.Pp
209.\"  XXX  IMPORTANT:  If/when the /proc-based code is pulled out,
210.\"  remove all references to the -K option, and the paragraph
211.\"  below.  It might be a good idea to keep -K around for one
212.\"  release, and have it print a warning that -K is deprecated.
213.\"  - bgrayson
214If
215.Nm
216is unable to extract process information directly from the
217kernel (e.g., due to an incorrect
218.Fl N
219option or kvm-based reasons), it currently uses an experimental
220fallback method to gather as much information as possible through the
221limited
222.Dq Pa /proc
223interface, if the
224.Dq Pa /proc
225filesystem is mounted.  See
226.Xr mount_procfs 8
227for more details.
228.Nm
229verifies that
230.Dq Pa /proc
231is a procfs filesystem before proceeding.  This experimental
232fallback method will change in future releases.  The
233.Fl K
234option disables this fallback /proc-based lookup.
235.Pp
236A complete list of the available keywords are listed below.
237Some of these keywords are further specified as follows:
238.Bl -tag -width indent
239.It %cpu
240The cpu utilization of the process; this is a decaying average over up to
241a minute of previous (real) time.
242Since the time base over which this is computed varies (since processes may
243be very young) it is possible for the sum of all
244.Tn %CPU
245fields to exceed 100%.
246.It %mem
247The percentage of real memory used by this process.
248.It flags
249The flags (in hexadecimal) associated with the process as in
250the include file
251.Aq Pa sys/proc.h :
252.Bl -column P_NOCLDSTOP P_NOCLDSTOP
253.It Dv "P_ADVLOCK" Ta No "0x0000001	process may hold a POSIX advisory lock"
254.It Dv "P_CONTROLT" Ta No "0x0000002	process has a controlling terminal"
255.It Dv "P_INMEM" Ta No "0x0000004	process is loaded into memory"
256.It Dv "P_NOCLDSTOP" Ta No "0x0000008	no
257.Dv SIGCHLD
258when children stop
259.It Dv "P_PPWAIT" Ta No "0x0000010	parent is waiting for child to exec/exit"
260.It Dv "P_PROFIL" Ta No "0x0000020	process has started profiling"
261.It Dv "P_SELECT" Ta No "0x0000040	selecting; wakeup/waiting danger"
262.It Dv "P_SINTR" Ta No "0x0000080	sleep is interruptible"
263.It Dv "P_SUGID" Ta No "0x0000100	process had set id privileges since last exec"
264.It Dv "P_SYSTEM" Ta No "0x0000200	system process: no sigs, stats or swapping"
265.It Dv "P_TIMEOUT" Ta No "0x0000400	timing out during sleep"
266.It Dv "P_TRACED" Ta No "0x0000800	process is being traced"
267.It Dv "P_WAITED" Ta No "0x0001000	debugging process has waited for child"
268.It Dv "P_WEXIT" Ta No "0x0002000	working on exiting"
269.It Dv "P_EXEC" Ta No "0x0004000	process called"
270.Xr execve 2
271.It Dv "P_OWEUPC" Ta No "0x0008000	owe process an addupc() call at next ast"
272.\" the routine addupc is not documented in the man pages
273.It Dv "P_FSTRACE" Ta No "0x0010000	tracing via file system"
274.It Dv "P_NOCLDWAIT" Ta No "0x0020000	no zombies when children die"
275.El
276.It lim
277The soft limit on memory used, specified via a call to
278.Xr setrlimit 2 .
279.It lstart
280The exact time the command started, using the ``%C'' format described in
281.Xr strftime 3 .
282.It nice
283The process scheduling increment (see
284.Xr setpriority 2 ) .
285.It rss
286the real memory (resident set) size of the process (in 1024 byte units).
287.It start
288The time the command started.
289If the command started less than 24 hours ago, the start time is
290displayed using the ``%l:%M%p'' format described in
291.Xr strftime 3 .
292If the command started less than 7 days ago, the start time is
293displayed using the ``%a%p'' format.
294Otherwise, the start time is displayed using the ``%e%b%y'' format.
295.It state
296The state is given by a sequence of letters, for example,
297.Dq Tn RWNA .
298The first letter indicates the run state of the process:
299.Pp
300.Bl -tag -width indent -compact
301.It D
302Marks a process in disk (or other short term, uninterruptible) wait.
303.It I
304Marks a process that is idle (sleeping for longer than about 20 seconds).
305.It R
306Marks a runnable process.
307.It S
308Marks a process that is sleeping for less than about 20 seconds.
309.It T
310Marks a stopped process.
311.It Z
312Marks a dead process (a ``zombie'').
313.El
314.Pp
315Additional characters after these, if any, indicate additional state
316information:
317.Pp
318.Bl -tag -width indent -compact
319.It +
320The process is in the foreground process group of its control terminal.
321.It \*[Lt]
322The process has raised
323.Tn CPU
324scheduling priority.
325.It \*[Gt]
326The process has specified a soft limit on memory requirements and is
327currently exceeding that limit; such a process is (necessarily) not
328swapped.
329.It A
330the process has asked for random page replacement
331.Pf ( Dv VA_ANOM ,
332from
333.Xr madvise 2 ,
334for example, a LISP interpreter in a garbage collect).
335.It E
336The process is trying to exit.
337.It K
338The process is a kernel thread or system process.
339.It L
340The process has pages locked in core (for example, for raw
341.Tn I/O ) .
342.It N
343The process has reduced
344.Tn CPU
345scheduling priority (see
346.Xr setpriority 2 ) .
347.It S
348The process has asked for
349.Tn FIFO
350page replacement
351.Pf ( Dv VA_SEQL ,
352from
353.Xr madvise 2 ,
354for example, a large image processing program using virtual memory to
355sequentially address voluminous data).
356.It s
357The process is a session leader.
358.It V
359The process is suspended during a
360.Xr vfork 2 .
361.It W
362The process is swapped out.
363.It X
364The process is being traced or debugged.
365.El
366.It tt
367An abbreviation for the pathname of the controlling terminal, if any.
368The abbreviation consists of the two letters following
369.Dq Pa /dev/tty ,
370or, for the console, ``co''.
371This is followed by a ``-'' if the process can no longer reach that
372controlling terminal (i.e., it has been revoked).
373.It wchan
374The event (an address in the system) on which a process waits.
375When printed numerically, the initial part of the address is
376trimmed off and the result is printed in hex, for example, 0x80324000 prints
377as 324000.
378.El
379.Pp
380When printing using the command keyword, a process that has exited and
381has a parent that has not yet waited for the process (in other words, a zombie)
382is listed as ``\*[Lt]defunct\*[Gt]'', and a process which is blocked while trying
383to exit is listed as ``\*[Lt]exiting\*[Gt]''.
384.Pp
385.Nm
386will try to locate the processes' argument vector from the user
387area in order to print the command name and arguments. This method
388is not reliable because a process is allowed to destroy this
389information. The ucomm (accounting) keyword will always contain
390the real command name as contained in the process structure's p_comm field.
391.Pp
392If the command vector cannot be located (usually because it has not
393been set, as is the case of system processes and/or kernel threads)
394the command name is printed within square brackets.
395.Pp
396To indicate that the argument vector has been tampered with,
397.Nm
398will append the real command name to the output within parentheses
399if the basename of the first argument in the argument vector
400does not match the contents of the real command name.
401.Pp
402In addition,
403.Nm
404checks for the following two situations and does not append the
405real command name parenthesized:
406.Bl -tag -width indent
407.It -shellname
408The login process traditionally adds a
409.Sq -
410in front of the shell name to indicate a login shell.
411.Nm
412will not append parenthesized the command name if it matches with
413the name in the the first argument of the argument vector, skipping
414the leading
415.Sq - .
416.It daemonname: current-activity
417Daemon processes frequently report their current activity by setting
418their name to be like ``daemonname: current-activity''.
419.Nm
420will not append parenthesized the command name, if the string preceding the
421.Sq \&:
422in the first argument of the argument vector matches the command name.
423.El
424.Sh KEYWORDS
425The following is a complete list of the available keywords and their
426meanings.
427Several of them have aliases (keywords which are synonyms).
428.Pp
429.Bl -tag -width sigignore -compact
430.It %cpu
431percentage cpu usage (alias pcpu)
432.It %mem
433percentage memory usage (alias pmem)
434.It acflag
435accounting flag (alias acflg)
436.It command
437command and arguments
438.It cpu
439short-term cpu usage factor (for scheduling)
440.It flags
441the process flags, in hexadecimal (alias f)
442.It inblk
443total blocks read (alias inblock)
444.It jobc
445job control count
446.It holdcnt
447number of holds on the process (if non-zero, process can't be swapped)
448.It ktrace
449tracing flags
450.It ktracep
451tracing vnode
452.It lim
453memoryuse limit
454.It logname
455login name of user who started the process
456.It lstart
457time started
458.It majflt
459total page faults
460.It minflt
461total page reclaims
462.It msgrcv
463total messages received (reads from pipes/sockets)
464.It msgsnd
465total messages sent (writes on pipes/sockets)
466.It nice
467nice value (alias ni)
468.It nivcsw
469total involuntary context switches
470.It nsigs
471total signals taken (alias nsignals)
472.It nswap
473total swaps in/out
474.It nvcsw
475total voluntary context switches
476.It nwchan
477wait channel (as an address)
478.It oublk
479total blocks written (alias oublock)
480.It p_ru
481resource usage (valid only for zombie)
482.It paddr
483kernel virtual address of the
484.Tn "struct proc"
485belonging to the process.
486.It pagein
487pageins (same as majflt)
488.It pgid
489process group number
490.It pid
491process
492.Tn ID
493.It ppid
494parent process
495.Tn ID
496.It pri
497scheduling priority
498.It re
499core residency time (in seconds; 127 = infinity)
500.It rgid
501real group
502.Tn ID
503.It rlink
504reverse link on run queue, or 0
505.It rss
506resident set size
507.It rsz
508resident set size + (text size / text use count) (alias rssize)
509.It ruid
510real user
511.Tn ID
512.It ruser
513user name (from ruid)
514.It sess
515session pointer
516.It sig
517pending signals (alias pending)
518.It sigcatch
519caught signals (alias caught)
520.It sigignore
521ignored signals (alias ignored)
522.It sigmask
523blocked signals (alias blocked)
524.It sl
525sleep time (in seconds; 127 = infinity)
526.It start
527time started
528.It state
529symbolic process state (alias stat)
530.It svgid
531saved gid from a setgid executable
532.It svuid
533saved uid from a setuid executable
534.It tdev
535control terminal device number
536.It time
537accumulated cpu time, user + system (alias cputime)
538.It tpgid
539control terminal process group
540.Tn ID
541.It tsess
542control terminal session pointer
543.It tsiz
544text size (in Kbytes)
545.It tt
546control terminal name (two letter abbreviation)
547.It tty
548full name of control terminal
549.It ucomm
550name to be used for accounting
551.It uid
552effective user
553.Tn ID
554.It upr
555scheduling priority on return from system call (alias usrpri)
556.It user
557user name (from uid)
558.It vsz
559virtual size in Kbytes (alias vsize)
560.It wchan
561wait channel (as a symbolic name)
562.It xstat
563exit or stop status (valid only for stopped or zombie process)
564.El
565.Sh FILES
566.Bl -tag -width /var/db/kvm.db -compact
567.It Pa /dev
568special files and device names
569.It Pa /dev/drum
570default swap device
571.It Pa /dev/kmem
572default kernel memory
573.It Pa /var/run/dev.db
574/dev name database
575.It Pa /var/db/kvm.db
576system namelist database
577.It Pa /netbsd
578default system namelist
579.It Pa /proc
580filesystem for obtaining process information
581.El
582.Sh SEE ALSO
583.Xr kill 1 ,
584.Xr pgrep 1 ,
585.Xr pkill 1 ,
586.Xr sh 1 ,
587.Xr w 1 ,
588.Xr kvm 3 ,
589.Xr strftime 3 ,
590.Xr mount_procfs 8 ,
591.Xr pstat 8
592.Sh BUGS
593Since
594.Nm
595cannot run faster than the system and is run as any other scheduled
596process, the information it displays can never be exact.
597