OSDN Git Service

(split) LDP_man-pages: update original to v3.35.
[linuxjm/LDP_man-pages.git] / original / man7 / man-pages.7
1 .\" (C) Copyright 1992-1999 Rickard E. Faith and David A. Wheeler
2 .\" (faith@cs.unc.edu and dwheeler@ida.org)
3 .\" and (C) Copyright 2007 Michael Kerrisk <mtk.manpages@gmail.com>
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" 2007-05-30 created by mtk, using text from old man.7 plus
26 .\" rewrites and additional text.
27 .\"
28 .TH MAN-PAGES 7 2008-10-28 "Linux" "Linux Programmer's Manual"
29 .SH NAME
30 man-pages \- conventions for writing Linux man pages
31 .SH SYNOPSIS
32 .B man
33 .RI [ section ]
34 .I title
35 .SH DESCRIPTION
36 This page describes the conventions that should be employed
37 when writing man pages for the Linux \fIman-pages\fP project,
38 which comprises Sections 2, 3, 4, 5, and 7 of the Linux manual pages.
39 The conventions described on this page may also be useful
40 for authors writing man pages for other projects.
41 .SS Sections of the Manual Pages
42 .PP
43 The manual Sections are traditionally defined as follows:
44 .TP 10
45 .B 1 Commands (Programs)
46 Those commands that can be executed by the user from within
47 a shell.
48 .TP
49 .B 2 System calls
50 Those functions which must be performed by the kernel.
51 .TP
52 .B 3 Library calls
53 Most of the
54 .I libc
55 functions.
56 .TP
57 .B 4 Special files (devices)
58 Files found in
59 .IR /dev .
60 .TP
61 .B 5 File formats and conventions
62 The format for
63 .I /etc/passwd
64 and other human-readable files.
65 .TP
66 .B 6 Games
67 .TP
68 .B 7 Conventions and miscellaneous
69 Overviews of various topics, conventions and protocols,
70 character set standards, and miscellaneous other things.
71 .TP
72 .B 8 System management commands
73 Commands like
74 .BR mount (8),
75 many of which only root can execute.
76 .\" .TP
77 .\" .B 9 Kernel routines
78 .\" This is an obsolete manual section.
79 .\" Once it was thought a good idea to document the Linux kernel here,
80 .\" but in fact very little has been documented, and the documentation
81 .\" that exists is outdated already.
82 .\" There are better sources of
83 .\" information for kernel developers.
84 .SS Macro package
85 New manual pages should be marked up using the
86 .B groff an.tmac
87 package described in
88 .BR man (7).
89 This choice is mainly for consistency: the vast majority of
90 existing Linux manual pages are marked up using these macros.
91 .SS Conventions for source file layout
92 Please limit source code line length to no more than about 75 characters
93 wherever possible.
94 This helps avoid line-wrapping in some mail clients when patches are
95 submitted inline.
96
97 New sentences should be started on new lines.
98 This makes it easier to see the effect of patches,
99 which often operate at the level of individual sentences.
100 .SS Title line
101 The first command in a man page should be a \fBTH\fP command:
102 .RS
103 .sp
104 .B \&.TH
105 .I "title section date source manual"
106 .sp
107 .RE
108 where:
109 .RS
110 .TP 10
111 .I title
112 The title of the man page, written in all caps (e.g.,
113 .IR MAN-PAGES ).
114 .TP
115 .I section
116 The section number in which the man page should be placed (e.g.,
117 .IR 7 ).
118 .TP
119 .I date
120 The date of the last revision\(emremember to change this every time a
121 change is made to the man page,
122 since this is the most general way of doing version control.
123 Dates should be written in the form YYYY-MM-DD.
124 .TP
125 .I source
126 The source of the command, function, or system call.
127
128 For those few \fIman-pages\fP pages in Sections 1 and 8,
129 probably you just want to write
130 .IR GNU .
131
132 For system calls, just write
133 .IR "Linux" .
134 (An earlier practice was to write the version number
135 of the kernel from which the manual page was being written/checked.
136 However, this was never done consistently, and so was
137 probably worse than including no version number.
138 Henceforth, avoid including a version number.)
139
140 For library calls that are part of glibc or one of the
141 other common GNU libraries, just use
142 .IR "GNU C Library" ", " GNU ,
143 or an empty string.
144
145 For Section 4 pages, use
146 .IR "Linux" .
147
148 In cases of doubt, just write
149 .IR Linux ", or " GNU .
150 .TP
151 .I manual
152 The title of the manual (e.g., for Section 2 and 3 pages in
153 the \fIman-pages\fP package, use
154 .IR "Linux Programmer's Manual" ).
155 .RE
156 .SS Sections within a manual page
157 The list below shows conventional or suggested sections.
158 Most manual pages should include at least the
159 .B highlighted
160 sections.
161 Arrange a new manual page so that sections
162 are placed in the order shown in the list.
163 .in +0.5i
164 .nf
165
166 \fBNAME\fP
167 \fBSYNOPSIS\fP
168 CONFIGURATION      [Normally only in Section 4]
169 \fBDESCRIPTION\fP
170 OPTIONS            [Normally only in Sections 1, 8]
171 EXIT STATUS        [Normally only in Sections 1, 8]
172 RETURN VALUE       [Normally only in Sections 2, 3]
173 .\" May 07: Few current man pages have an ERROR HANDLING section,,,
174 .\" ERROR HANDLING,
175 ERRORS             [Typically only in Sections 2, 3]
176 .\" May 07: Almost no current man pages have a USAGE section,,,
177 .\" USAGE,
178 .\" DIAGNOSTICS,
179 .\" May 07: Almost no current man pages have a SECURITY section,,,
180 .\" SECURITY,
181 ENVIRONMENT
182 FILES
183 VERSIONS           [Normally only in Sections 2, 3]
184 CONFORMING TO
185 NOTES
186 BUGS
187 EXAMPLE
188 .\" AUTHORS sections are discouraged
189 .\" AUTHORS             [Discouraged]
190 \fBSEE ALSO\fP
191
192 .fi
193 .in
194 .IR "Where a traditional heading would apply" ", " "please use it" ;
195 this kind of consistency can make the information easier to understand.
196 If you must, you can create your own
197 headings if they make things easier to understand (this can
198 be especially useful for pages in Sections 4 and 5).
199 However, before doing this, consider whether you could use the
200 traditional headings, with some subsections (\fI.SS\fP) within
201 those sections.
202
203 The following list elaborates on the contents of each of
204 the above sections.
205 .TP 14
206 .B NAME
207 The name of this manual page.
208 See
209 .BR man (7)
210 for important details of the line(s) that should follow the
211 \fB.SH NAME\fP command.
212 .TP
213 .B SYNOPSIS
214 briefly describes the command or function's interface.
215 For commands, this shows the syntax of the command and its arguments
216 (including options);
217 boldface is used for as-is text and italics are used to
218 indicate replaceable arguments.
219 Brackets ([]) surround optional arguments, vertical bars (|)
220 separate choices, and ellipses (\&...) can be repeated.
221 For functions, it shows any required data declarations or
222 .B #include
223 directives, followed by the function declaration.
224
225 Where a feature test macro must be defined in order to obtain
226 the declaration of a function (or a variable) from a header file,
227 then the SYNOPSIS should indicate this, as described in
228 .BR feature_test_macros (7).
229 .\" FIXME . Say something here about compiler options
230 .TP
231 .B CONFIGURATION
232 Configuration details for a device.
233 This section normally only appears in Section 4 pages.
234 .TP
235 .B DESCRIPTION
236 gives an explanation of what the program, function, or format does.
237 Discuss how it interacts with files and standard input, and what it
238 produces on standard output or standard error.
239 Omit internals and implementation details unless they're critical for
240 understanding the interface.
241 Describe the usual case;
242 for information on command-line options of a program use the
243 .B OPTIONS
244 section.
245 .\" If there is some kind of input grammar or complex set of subcommands,
246 .\" consider describing them in a separate
247 .\" .B USAGE
248 .\" section (and just place an overview in the
249 .\" .B DESCRIPTION
250 .\" section).
251 .TP
252 .B OPTIONS
253 describes the command-line options accepted by a
254 program and how they change its behavior.
255 This section should only appear for Section 1 and 8 manual pages.
256 .\" .TP
257 .\" .B USAGE
258 .\" describes the grammar of any sublanguage this implements.
259 .TP
260 .B EXIT STATUS
261 lists the possible exit status values of a program and
262 the conditions that cause these values to be returned.
263 This section should only appear for Section 1 and 8 manual pages.
264 .TP
265 .B RETURN VALUE
266 For Section 2 and 3 pages, this section gives a
267 list of the values the library routine will return to the caller
268 and the conditions that cause these values to be returned.
269 .TP
270 .B ERRORS
271 For Section 2 and 3 manual pages, this is a list of the
272 values that may be placed in
273 .I errno
274 in the event of an error, along with information about the cause
275 of the errors.
276 .IR "The error list should be in alphabetical order" .
277 .TP
278 .B ENVIRONMENT
279 lists all environment variables that affect the program or function
280 and how they affect it.
281 .TP
282 .B FILES
283 lists the files the program or function uses, such as
284 configuration files, startup files,
285 and files the program directly operates on.
286 Give the full pathname of these files, and use the installation
287 process to modify the directory part to match user preferences.
288 For many programs, the default installation location is in
289 .IR /usr/local ,
290 so your base manual page should use
291 .I /usr/local
292 as the base.
293 .\" May 07: Almost no current man pages have a DIAGNOSTICS section;
294 .\"         "RETURN VALUE" or "EXIT STATUS" is preferred.
295 .\" .TP
296 .\" .B DIAGNOSTICS
297 .\" gives an overview of the most common error messages and how to
298 .\" cope with them.
299 .\" You don't need to explain system error messages
300 .\" or fatal signals that can appear during execution of any program
301 .\" unless they're special in some way to the program.
302 .\"
303 .\" May 07: Almost no current man pages have a SECURITY section.
304 .\".TP
305 .\".B SECURITY
306 .\"discusses security issues and implications.
307 .\"Warn about configurations or environments that should be avoided,
308 .\"commands that may have security implications, and so on, especially
309 .\"if they aren't obvious.
310 .\"Discussing security in a separate section isn't necessary;
311 .\"if it's easier to understand, place security information in the
312 .\"other sections (such as the
313 .\" .B DESCRIPTION
314 .\" or
315 .\" .B USAGE
316 .\" section).
317 .\" However, please include security information somewhere!
318 .TP
319 .B VERSIONS
320 A brief summary of the Linux kernel or glibc versions where a
321 system call or library function appeared,
322 or changed significantly in its operation.
323 As a general rule, every new interface should
324 include a VERSIONS section in its manual page.
325 Unfortunately,
326 many existing manual pages don't include this information
327 (since there was no policy to do so when they were written).
328 Patches to remedy this are welcome,
329 but, from the perspective of programmers writing new code,
330 this information probably only matters in the case of kernel
331 interfaces that have been added in Linux 2.4 or later
332 (i.e., changes since kernel 2.2),
333 and library functions that have been added to glibc since version 2.1
334 (i.e., changes since glibc 2.0).
335
336 The
337 .BR syscalls (2)
338 manual page also provides information about kernel versions
339 in which various system calls first appeared.
340 .TP
341 .B CONFORMING TO
342 describes any standards or conventions that relate to the function
343 or command described by the manual page.
344 For a page in Section 2 or 3,
345 this section should note the POSIX.1
346 version(s) that the call conforms to,
347 and also whether the call is specified in C99.
348 (Don't worry too much about other standards like SUS, SUSv2, and XPG,
349 or the SVr4 and 4.xBSD implementation standards,
350 unless the call was specified in those standards,
351 but isn't in the current version of POSIX.1.)
352 (See
353 .BR standards (7).)
354
355 If the call is not governed by any standards but commonly
356 exists on other systems, note them.
357 If the call is Linux-specific, note this.
358
359 If this section consists of just a list of standards
360 (which it commonly does),
361 terminate the list with a period (\(aq.\(aq).
362 .TP
363 .B NOTES
364 provides miscellaneous notes.
365 For Section 2 and 3 man pages you may find it useful to include
366 subsections (\fBSS\fP) named \fILinux Notes\fP and \fIGlibc Notes\fP.
367 .TP
368 .B BUGS
369 lists limitations, known defects or inconveniences,
370 and other questionable activities.
371 .TP
372 .B EXAMPLE
373 provides one or more examples describing how this function, file or
374 command is used.
375 For details on writing example programs,
376 see \fIExample Programs\fP below.
377 .TP
378 .B AUTHORS
379 lists authors of the documentation or program.
380 \fBUse of an AUTHORS section is strongly discouraged\fP.
381 Generally, it is better not to clutter every page with a list
382 of (over time potentially numerous) authors;
383 if you write or significantly amend a page,
384 add a copyright notice as a comment in the source file.
385 If you are the author of a device driver and want to include
386 an address for reporting bugs, place this under the BUGS section.
387 .TP
388 .B SEE ALSO
389 provides a comma-separated list of related man pages,
390 ordered by section number and
391 then alphabetically by name, possibly followed by
392 other related pages or documents.
393 Do not terminate this with a period.
394 .SS Font conventions
395 .PP
396 For functions, the arguments are always specified using italics,
397 .IR "even in the SYNOPSIS section" ,
398 where the rest of the function is specified in bold:
399 .PP
400 .BI "    int myfunction(int " argc ", char **" argv );
401 .PP
402 Variable names should, like argument names, be specified in italics.
403 .PP
404 Filenames (whether pathnames, or references to files in the
405 .I /usr/include
406 directory)
407 are always in italics (e.g.,
408 .IR <stdio.h> ),
409 except in the SYNOPSIS section, where included files are in bold (e.g.,
410 .BR "#include <stdio.h>" ).
411 When referring to a standard include file under
412 .IR /usr/include ,
413 specify the header file surrounded by angle brackets,
414 in the usual C way (e.g.,
415 .IR <stdio.h> ).
416 .PP
417 Special macros, which are usually in upper case, are in bold (e.g.,
418 .BR MAXINT ).
419 Exception: don't boldface NULL.
420 .PP
421 When enumerating a list of error codes, the codes are in bold (this list
422 usually uses the
423 .B \&.TP
424 macro).
425 .PP
426 Complete commands should, if long,
427 be written as in an indented line on their own, for example
428 .in +4n
429 .nf
430
431 man 7 man-pages
432
433 .fi
434 .in
435 If the command is short, then it can be included inline in the text,
436 in italic format, for example,
437 .IR "man 7 man-pages" .
438 In this case, it may be worth using nonbreaking spaces
439 ("\e\ ") at suitable places in the command.
440 Command options should be written in italics, e.g.,
441 .IR \-l .
442 .PP
443 Expressions, if not written on a separate indented line, should
444 be specified in italics.
445 Again, the use of nonbreaking spaces may be appropriate
446 if the expression is inlined with normal text.
447 .PP
448 Any reference to the subject of the current manual page
449 should be written with the name in bold.
450 If the subject is a function (i.e., this is a Section 2 or 3 page),
451 then the name should be followed by a pair of parentheses
452 in Roman (normal) font.
453 For example, in the
454 .BR fcntl (2)
455 man page, references to the subject of the page would be written as:
456 .BR fcntl ().
457 The preferred way to write this in the source file is:
458 .nf
459
460     .BR fcntl ()
461
462 .fi
463 (Using this format, rather than the use of "\\fB...\\fP()"
464 makes it easier to write tools that parse man page source files.)
465 .PP
466 Any reference to another man page
467 should be written with the name in bold,
468 \fIalways\fP followed by the section number,
469 formatted in Roman (normal) font, without any
470 separating spaces (e.g.,
471 .BR intro (2)).
472 The preferred way to write this in the source file is:
473 .nf
474
475     .BR intro (2)
476
477 .fi
478 (Including the section number in cross references lets tools like
479 .BR man2html (1)
480 create properly hyperlinked pages.)
481 .SS Spelling
482 Starting with release 2.59,
483 .I man-pages
484 follows American spelling conventions;
485 please write all new pages and patches according to these conventions.
486 .SS Example Programs and Shell Sessions
487 Manual pages can include example programs demonstrating how to
488 use a system call or library function.
489 However, note the following:
490 .TP 3
491 *
492 Example programs should be written in C.
493 .TP
494 *
495 An example program is only necessary and useful if it demonstrates
496 something beyond what can easily be provided in a textual
497 description of the interface.
498 An example program that does nothing
499 other than call an interface usually serves little purpose.
500 .TP
501 *
502 Example programs should be fairly short (preferably less than 100 lines;
503 ideally less than 50 lines).
504 .TP
505 *
506 Example programs should do error checking after system calls and
507 library function calls.
508 .TP
509 *
510 Example programs should be complete, and compile without
511 warnings when compiled with \fIcc\ \-Wall\fP.
512 .TP
513 *
514 Where possible and appropriate, example programs should allow
515 experimentation, by varying their behavior based on inputs
516 (ideally from command-line arguments, or alternatively, via
517 input read by the program).
518 .TP
519 *
520 Example programs should be laid out according to Kernighan and
521 Ritchie style, with 4-space indents.
522 (Avoid the use of TAB characters in source code!)
523 .PP
524 For some examples of what example programs should look like, see
525 .BR wait (2)
526 and
527 .BR pipe (2).
528
529 If you include a shell session demonstrating the use of a program
530 or other system feature, boldface the user input text,
531 to distinguish it from output produced by the system.
532 .SS Indentation of structure definitions, shell session logs, etc.
533 When structure definitions, shell session logs, etc. are included
534 in running text, indent them by 4 spaces (i.e., a block enclosed by
535 .I ".in\ +4n"
536 and
537 .IR ".in" ).
538 .SH EXAMPLE
539 For canonical examples of how man pages in the
540 .I man-pages
541 package should look, see
542 .BR pipe (2)
543 and
544 .BR fcntl (2).
545 .SH SEE ALSO
546 .BR man (1),
547 .BR man2html (1),
548 .BR groff (7),
549 .BR groff_man (7),
550 .BR man (7),
551 .BR mdoc (7)