xref: /openbsd-src/usr.bin/top/top.1 (revision 41ce3b17e73f6b7d2d9e1a3d961e4bab2d895cb5)
1.\"	$OpenBSD: top.1,v 1.81 2022/03/31 17:27:28 naddy Exp $
2.\"
3.\" Copyright (c) 1997, Jason Downs.  All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
15.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17.\" DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
18.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.Dd $Mdocdate: March 31 2022 $
27.Dt TOP 1
28.Os
29.Sh NAME
30.Nm top
31.Nd display and update information about the top CPU processes
32.Sh SYNOPSIS
33.Nm top
34.Bk -words
35.Op Fl 1bCHIinqStu
36.Op Fl d Ar count
37.Op Fl g Ar string
38.Op Fl o Oo - Oc Ns Ar field
39.Op Fl p Ar pid
40.Op Fl s Ar time
41.Op Fl T Oo - Oc Ns Ar rtable
42.Op Fl U Oo - Oc Ns Ar user
43.Op Ar number
44.Ek
45.Sh DESCRIPTION
46.Nm
47displays the top processes on the system and periodically updates this
48information.
49If standard output is an intelligent terminal (see below) then
50as many processes as will fit on the terminal screen are displayed
51by default.
52Otherwise, a good number of them are shown (around 20).
53Raw CPU percentage is used to rank the processes.
54If
55.Ar number
56is given, then the top
57.Ar number
58processes will be displayed instead of the default.
59.Pp
60.Nm
61makes a distinction between terminals that support advanced capabilities
62and those that do not.
63This distinction affects the choice of defaults for certain options.
64In the remainder of this document, an
65.Em intelligent
66terminal is one that supports cursor addressing, clear screen, and clear
67to end of line.
68Conversely, a
69.Em dumb
70terminal is one that does not support such features.
71If the output of
72.Nm
73is redirected to a file, it acts as if it were being run on a dumb
74terminal.
75.Pp
76The options are as follows:
77.Bl -tag -width Ds
78.It Fl 1
79Display combined CPU statistics for all processors on a single line
80instead of one line per CPU.
81If there are more than 8 CPUs detected in the system, this option
82is automatically enabled.
83.It Fl b
84Use
85.Em batch
86mode.
87In this mode, all input from the terminal is ignored.
88Interrupt characters (such as
89.Ql ^C
90and
91.Ql ^\e )
92still have an effect.
93This is the default on a dumb terminal, or when the output is not a terminal.
94.It Fl C
95Show command line arguments
96as well as the process itself.
97.It Fl d Ar count
98Show only
99.Ar count
100displays, then exit.
101A display is considered to be one update of the screen.
102This option allows the user to select the number of displays
103to be shown before
104.Nm
105automatically exits.
106For intelligent terminals, no upper limit is set.
107The default is 1 for dumb terminals.
108.It Fl g Ar string
109Display only processes that contain
110.Ar string
111in their command name.
112If displaying of arguments is enabled, the arguments are searched too.
113.It Fl H
114Show process threads in the display.
115Normally, only the main process is shown.
116This option makes all threads visible.
117.It Fl I
118Do not display idle processes.
119By default,
120.Nm
121displays both active and idle processes.
122.It Fl i
123Use
124.Em interactive
125mode.
126In this mode, any input is immediately read for processing.
127See the section on
128.Sx INTERACTIVE MODE
129for an explanation of which keys perform what functions.
130After the command
131is processed, the screen will immediately be updated, even if the command was
132not understood.
133This mode is the default when standard output is an intelligent terminal.
134.It Fl n
135Use
136.Em non-interactive
137mode.
138This is identical to
139.Em batch
140mode.
141.It Fl o Oo - Oc Ns Ar field
142Sort the process display area using the specified
143.Ar field
144as the primary key.
145The field name is the name of the column as seen in the output,
146but in lower case.
147The
148.Sq -
149prefix reverses the order.
150The
151.Ox
152version of
153.Nm
154supports
155.Ar cpu ,
156.Ar size ,
157.Ar res ,
158.Ar time ,
159.Ar pri ,
160.Ar pid ,
161and
162.Ar command .
163.It Fl p Ar pid
164Show only the process
165.Ar pid .
166.It Fl q
167Renice
168.Nm
169to \-20 so that it will run faster.
170This can be used when the system is
171being very sluggish to improve the possibility of discovering the problem.
172This option can only be used by root.
173.It Fl S
174Show system processes in the display.
175Normally, system processes such as the pager and the swapper are not shown.
176This option makes them visible.
177.It Fl s Ar time
178Set the delay between screen updates to
179.Ar time
180seconds.
181The value may be fractional, to permit delays of less than 1 second.
182The default delay between updates is 5 seconds.
183.It Fl T Oo - Oc Ns Ar rtable
184Display only processes associated with the specified routing table
185.Ar rtable .
186.Sq T+
187shows processes associated with all routing tables.
188The
189.Sq -
190prefix hides processes associated with a single routing table.
191.It Fl t
192Display routing tables.
193By default, routing tables are not shown.
194.It Fl U Oo - Oc Ns Ar user
195Show only those processes owned by username or UID
196.Ar user .
197The prefix
198.Sq -
199hides processes owned by that user.
200.It Fl u
201Do not take the time to map UID numbers to usernames.
202Normally,
203.Nm
204will read as much of the password database as is necessary to map
205all the user ID numbers it encounters into login names.
206This option
207disables all that, while possibly decreasing execution time.
208The UID numbers are displayed instead of the names.
209.El
210.Pp
211Both
212.Ar count
213and
214.Ar number
215fields can be specified as
216.Li infinite ,
217indicating that they can stretch as far as possible.
218This is accomplished by using any proper prefix of the keywords
219.Li infinity ,
220.Li maximum ,
221or
222.Li all .
223The default for
224.Ar count
225on an intelligent terminal is, in fact,
226.Li infinity .
227.Pp
228The environment variable
229.Ev TOP
230is examined for options before the command line is scanned.
231This enables users to set their own defaults.
232The number of processes to display
233can also be specified in the environment variable
234.Ev TOP .
235.Pp
236The options
237.Fl I ,
238.Fl S ,
239and
240.Fl u
241are actually toggles.
242A second specification of any of these options
243will negate the first.
244Thus a user who has the environment variable
245.Ev TOP
246set to
247.Dq -I
248may use the command
249.Dq top -I
250to see idle processes.
251.Sh INTERACTIVE MODE
252When
253.Nm
254is running in
255.Em interactive mode ,
256it reads commands from the terminal and acts upon them accordingly.
257In this mode, the terminal is put in
258.Dv CBREAK ,
259so that a character will be processed as soon as it is typed.
260Almost always, a key will be pressed when
261.Nm
262is between displays; that is, while it is waiting for
263.Ar time
264seconds to elapse.
265If this is the case, the command will be
266processed and the display will be updated immediately thereafter
267(reflecting any changes that the command may have specified).
268This happens even if the command was incorrect.
269If a key is pressed while
270.Nm
271is in the middle of updating the display, it will finish the update and
272then process the command.
273Some commands require additional information,
274and the user will be prompted accordingly.
275While typing this information
276in, the user's erase and kill keys (as set up by the command
277.Xr stty 1 )
278are recognized, and a newline terminates the input.
279.Pp
280These commands are currently recognized (^L refers to control-L):
281.Bl -tag -width XxXXXX
282.It h | \&?
283Display a summary of the commands (help screen).
284.It ^L
285Redraw the screen.
286.It <space>
287Update the screen.
288.It q
289Quit
290.Nm .
291.El
292.Bl -tag -width XxXXXX
293.It +
294Reset any filters put in place by the
295.Sq g ,
296.Sq p ,
297and
298.Sq u
299interactive commands,
300or their command line equivalents,
301or any process highlighting put in place by the
302.Sq P
303interactive command.
304.It 1
305Toggle the display of per CPU or combined CPU statistics.
306.It 9 | 0
307Scroll up/down the process list by one line.
308.It \&( | \&)
309Scroll up/down the process list by screen half.
310.It C
311Toggle the display of process command line arguments.
312.It d Ar count
313Show only
314.Ar count
315displays,
316then exit.
317.It e
318Display a list of system errors (if any) generated by the last
319.Li kill
320or
321.Li renice
322command.
323.It g|/ Ar string
324Display only processes that contain
325.Ar string
326in their command name.
327If displaying of arguments is enabled, the arguments are searched too.
328.Sq g+
329or
330.Sq /+
331shows all processes.
332.It H
333Toggle the display of process threads.
334.It I | i
335Toggle the display of idle processes.
336.It Xo k
337.Op - Ns Ar sig
338.Ar pid
339.Xc
340Send signal
341.No - Ns Ar sig
342.Pf ( Dv TERM
343by default) to process
344.Ar pid .
345This acts similarly to the command
346.Xr kill 1 .
347.It n|# Ar count
348Show
349.Ar count
350processes.
351.It o Oo - Oc Ns Ar field
352Sort the process display area using the specified
353.Ar field
354as the primary key.
355The
356.Sq -
357prefix reverses the order.
358Values are the same as for the
359.Fl o
360flag, as detailed above.
361.It P Ar pid
362Highlight a specific process, selected by
363.Ar pid .
364.Sq P+
365removes process highlighting.
366.It p Ar pid
367Show only the process
368.Ar pid .
369.Sq p+
370shows all processes.
371.It r Ar count pid
372Change the priority (the
373.Em nice )
374of a list of processes to
375.Ar count
376for process
377.Ar pid .
378This acts similarly to the command
379.Xr renice 8 .
380.It S
381Toggle the display of system processes.
382.It s Ar time
383Set the delay between screen updates to
384.Ar time
385seconds.
386.It T Oo - Oc Ns Ar rtable
387Display only processes associated with the specified routing table
388.Ar rtable .
389.Sq T+
390shows processes associated with all routing tables.
391The
392.Sq -
393prefix hides processes associated with a single routing table.
394.It t
395Toggle the display of routing tables.
396.It u Oo - Oc Ns Ar user
397Show only those processes owned by username or UID
398.Ar user .
399.Sq u+
400shows processes belonging to all users.
401The
402.Sq -
403prefix hides processes belonging to a single
404.Ar user .
405.El
406.Sh THE DISPLAY
407.\" The actual display varies depending on the specific variant of Unix
408.\" that the machine is running.  This description may not exactly match
409.\" what is seen by top running on this particular machine.  Differences
410.\" are listed at the end of this manual entry.
411.\" .Pp
412The top few lines of the display show general information
413about the state of the system, including
414.\" the last process ID assigned to a process,
415.\" (on most systems),
416the three load average numbers,
417the hostname,
418the current time,
419the number of existing processes,
420the number of processes in each state
421(starting, running, idle, stopped, zombie, dead, and on processor),
422and a percentage of time spent in each of the processor states
423(user, nice, system, spinning, interrupt, and idle).
424It also includes information about physical and virtual memory allocation.
425The load average numbers give the number of jobs in the run queue averaged
426over 1, 5, and 15 minutes.
427.Pp
428The remainder of the screen displays information about individual
429processes.
430This display is similar in spirit to
431.Xr ps 1
432but it is not exactly the same.
433The following fields are displayed:
434.Bl -tag -width USERNAME -offset indent
435.It PID
436The process ID.
437.It USERNAME
438The name of the process's owner.
439.It TID
440The thread ID, used instead of USERNAME if
441.Fl H
442is specified.
443.It UID
444Used instead of USERNAME if
445.Fl u
446is specified.
447.It PRI
448The current priority of the process.
449.It NICE
450The nice amount (in the range \-20 to 20).
451.It SIZE
452The total size of the process (the text, data, and stack segments).
453.It RES
454The current amount of resident memory.
455.It STATE
456The current state (one of
457.Li start ,
458.Li run ,
459.Li sleep ,
460.Li stop ,
461.Li idle ,
462.Li zomb ,
463.Li dead ,
464or
465.Li onproc ) .
466On multiprocessor systems, this is followed by a slash and the CPU
467number on which the process is bound.
468.It WAIT
469A description of the wait channel the process is sleeping on if it's
470asleep.
471.It RTABLE
472The routing table, used instead of WAIT if
473.Fl t
474is specified.
475.It TIME
476The number of system and user CPU seconds that the process has used.
477.It CPU
478The raw percentage of CPU usage and the default field on which the
479display is sorted.
480.It COMMAND
481The name (and arguments if
482.Fl C
483is specified) of the command that the process is currently running.
484.El
485.Sh ENVIRONMENT
486.Bl -tag -width Ev
487.It Ev TOP
488User-configurable defaults for options.
489.El
490.Sh FILES
491.Bl -tag -width "/etc/passwdXXX" -compact
492.It Pa /dev/kmem
493kernel memory
494.It Pa /dev/mem
495physical memory
496.It Pa /etc/passwd
497used to map user ID to user
498.It Pa /bsd
499kernel image
500.El
501.Sh SEE ALSO
502.Xr fstat 1 ,
503.Xr kill 1 ,
504.Xr netstat 1 ,
505.Xr ps 1 ,
506.Xr stty 1 ,
507.Xr systat 1 ,
508.Xr mem 4 ,
509.Xr iostat 8 ,
510.Xr pstat 8 ,
511.Xr renice 8 ,
512.Xr vmstat 8
513.Sh AUTHORS
514.An William LeFebvre ,
515EECS Department, Northwestern University
516.Sh CAVEATS
517As with
518.Xr ps 1 ,
519.Nm
520only provides snapshots of a constantly changing system.
521