Section: Linux Programmer's Manual (7)
This page describes the conventions that should be employed when writing man pages for the Linux man-pages project, which documents the user-space API provided by the Linux kernel and the GNU C library. The project thus provides most of the pages in Section 2, as well as many of the pages that appear in Sections 3, 4, 5, and 7 of the man pages on a Linux system. The conventions described on this page may also be useful for authors writing man pages for other projects.
The manual Sections are traditionally defined as follows:
New manual pages should be marked up using the groff an.tmac package described in man?(7). This choice is mainly for consistency: the vast majority of existing Linux manual pages are marked up using these macros.
Please limit source code line length to no more than about 75 characters wherever possible. This helps avoid line-wrapping in some mail clients when patches are submitted inline.
The first command in a man page should be a TH command:
.TH title section date source manual
For those few man-pages pages in Sections 1 and 8, probably you just want to write GNU.
For system calls, just write Linux. (An earlier practice was to write the version number of the kernel from which the manual page was being written/checked. However, this was never done consistently, and so was probably worse than including no version number. Henceforth, avoid including a version number.)
For library calls that are part of glibc or one of the other common GNU libraries, just use GNU C Library, GNU, or an empty string.
For Section 4 pages, use Linux.
In cases of doubt, just write Linux, or GNU.
The list below shows conventional or suggested sections. Most manual pages should include at least the highlighted sections. Arrange a new manual page so that sections are placed in the order shown in the list.
NAME SYNOPSIS CONFIGURATION [Normally only in Section 4] DESCRIPTION OPTIONS [Normally only in Sections 1, 8] EXIT STATUS [Normally only in Sections 1, 8] RETURN VALUE [Normally only in Sections 2, 3] ERRORS [Typically only in Sections 2, 3] ENVIRONMENT FILES VERSIONS [Normally only in Sections 2, 3] ATTRIBUTES [Normally only in Sections 2, 3] CONFORMING TO NOTES BUGS EXAMPLE SEE ALSO
Where a traditional heading would apply, please use it; this kind of consistency can make the information easier to understand. If you must, you can create your own headings if they make things easier to understand (this can be especially useful for pages in Sections 4 and 5). However, before doing this, consider whether you could use the traditional headings, with some subsections (.SS) within those sections.
The following list elaborates on the contents of each of the above sections.
See man?(7) for important details of the line(s) that should follow the .SH NAME command. All words in this line (including the word immediately following the "\-") should be in lowercase, except where English or technical terminological convention dictates otherwise.
For commands, this shows the syntax of the command and its arguments (including options); boldface is used for as-is text and italics are used to indicate replaceable arguments. Brackets () surround optional arguments, vertical bars (|) separate choices, and ellipses (...) can be repeated. For functions, it shows any required data declarations or #include directives, followed by the function declaration.
Where a feature test macro must be defined in order to obtain the declaration of a function (or a variable) from a header file, then the SYNOPSIS should indicate this, as described in feature_test_macros?(7).
This section normally appears only in Section 4 pages.
Discuss how it interacts with files and standard input, and what it produces on standard output or standard error. Omit internals and implementation details unless they're critical for understanding the interface. Describe the usual case; for information on command-line options of a program use the OPTIONS section.
When describing new behavior or new flags for a system call or library function, be careful to note the kernel or C library version that introduced the change. The preferred method of noting this information for flags is as part of a .TP list, in the following form (here, for a new system call flag):
This section should appear only for Section 1 and 8 manual pages.
This section should appear only for Section 1 and 8 manual pages.
The error list should be in alphabetical order.
Give the full pathname of these files, and use the installation process to modify the directory part to match user preferences. For many programs, the default installation location is in /usr/local, so your base manual page should use /usr/local as the base.
The following subsections are defined:
As a general rule, every new interface should include a VERSIONS section in its manual page. Unfortunately, many existing manual pages don't include this information (since there was no policy to do so when they were written). Patches to remedy this are welcome, but, from the perspective of programmers writing new code, this information probably matters only in the case of kernel interfaces that have been added in Linux 2.4 or later (i.e., changes since kernel 2.2), and library functions that have been added to glibc since version 2.1 (i.e., changes since glibc 2.0).
For a page in Section 2 or 3, this section should note the POSIX.1 version(s) that the call conforms to, and also whether the call is specified in C99. (Don't worry too much about other standards like SUS, SUSv2, and XPG, or the SVr4 and 4.xBSD implementation standards, unless the call was specified in those standards, but isn't in the current version of POSIX.1.)
If the call is not governed by any standards but commonly exists on other systems, note them. If the call is Linux-specific, note this.
If this section consists of just a list of standards (which it commonly does), terminate the list with a period ('.').
For Section 2 and 3 man pages you may find it useful to include subsections (SS) named Linux Notes and Glibc Notes.
In Section 2, use the heading C library/kernel ABI differences to mark off notes that describe the differences (if any) between the C library wrapper function for a system call and the raw system call interface provided by the kernel.
For details on writing example programs, see Example Programs below.
Use of an AUTHORS section is strongly discouraged. Generally, it is better not to clutter every page with a list of (over time potentially numerous) authors; if you write or significantly amend a page, add a copyright notice as a comment in the source file. If you are the author of a device driver and want to include an address for reporting bugs, place this under the BUGS section.
The list should be ordered by section number and then alphabetically by name Do not terminate this with a period.
Where the SEE ALSO list contains many long manual page names, to improve the visual result of the output, it may be useful to employ the .ad l (don't right justify) and .nh (don't hyphenate) directives. Hyphenation of individual page names can be prevented by preceding words with the string "\%".:
The following subsections describe the preferred style for the man-pages project. For details not covered below, the Chicago Manual of Style is usually a good source; try also grepping for preexisting usage in the project source tree.
For functions, the arguments are always specified using italics, even in the SYNOPSIS section, where the rest of the function is specified in bold:
int myfunction(int argc, char **argv);
Variable names should, like argument names, be specified in italics.
Filenames (whether pathnames, or references to header files) are always in italics (e.g., <stdio.h>), except in the SYNOPSIS section, where included files are in bold (e.g., #include <stdio.h>). When referring to a standard header file include, specify the header file surrounded by angle brackets, in the usual C way (e.g., <stdio.h>).
Special macros, which are usually in uppercase, are in bold (e.g., MAXINT). Exception: don't boldface NULL.
When enumerating a list of error codes, the codes are in bold (this list usually uses the .TP macro).
Complete commands should, if long, be written as an indented line on their own, with a blank line before and after the command, for example
man 7 man-pages
If the command is short, then it can be included inline in the text, in italic format, for example, man 7 man-pages. In this case, it may be worth using nonbreaking spaces ("\ ") at suitable places in the command. Command options should be written in italics (e.g., -l).
Expressions, if not written on a separate indented line, should be specified in italics. Again, the use of nonbreaking spaces may be appropriate if the expression is inlined with normal text.
Any reference to the subject of the current manual page should be written with the name in bold. If the subject is a function (i.e., this is a Section 2 or 3 page), then the name should be followed by a pair of parentheses in Roman (normal) font. For example, in the fcntl?(2) man page, references to the subject of the page would be written as: fcntl(). The preferred way to write this in the source file is:
.BR fcntl ()
(Using this format, rather than the use of "\fB...\fP()" makes it easier to write tools that parse man page source files.)
Any reference to another man page should be written with the name in bold, always followed by the section number, formatted in Roman (normal) font, without any separating spaces (e.g., intro?(2)). The preferred way to write this in the source file is:
.BR intro (2)
Starting with release 2.59, man-pages follows American spelling conventions (previously, there was a random mix of British and American spellings); please write all new pages and patches according to these conventions.
Aside from the well-known spelling differences, there are a few other subtleties to watch for:
In subsection ("SS") headings, capitalize the first word in the heading, but otherwise use lowercase, except where English usage (e.g., proper nouns) or programming language requirements (e.g., identifier names) dictate otherwise. For example:
.SS Unicode under Linux
The following table lists some preferred terms to use in man pages, mainly to ensure consistency across pages.
<TABLE> <TR VALIGN="top| <TD>Term</TD> <TD>Avoid using</TD> <TD>Notes
</TD> </TR> <TR VALIGN="top| <TD></TD> </TR> <TR VALIGN="top| <TD>bit mask</TD> <TD>bitmask</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>built-in</TD> <TD>builtin</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>Epoch</TD> <TD>epoch</TD> <TD>For the UNIX Epoch (00:00:00, 1 Jan 1970 UTC)
</TD> </TR> <TR VALIGN="top| <TD>filename</TD> <TD>file name</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>filesystem</TD> <TD>file system</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>hostname</TD> <TD>host name</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>inode</TD> <TD>i-node</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>lowercase</TD> <TD>lower case, lower-case</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>pathname</TD> <TD>path name</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>pseudoterminal</TD> <TD>pseudo-terminal</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>privileged port</TD> <TD>reserved port, system port</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>real-time</TD> <TD>realtime, real time</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>run time</TD> <TD>runtime</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>saved set-group-ID</TD> <TD>saved group ID, saved set-GID</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>saved set-user-ID</TD> <TD>saved user ID, saved set-UID</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>set-group-ID</TD> <TD>set-GID, setgid</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>set-user-ID</TD> <TD>set-UID, setuid</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>superuser</TD> <TD>super user, super-user</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>superblock</TD> <TD>super block, super-block</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>timestamp</TD> <TD>time stamp</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>timezone</TD> <TD>time zone</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>uppercase</TD> <TD>upper case, upper-case</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>usable</TD> <TD>useable</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>user space</TD> <TD>userspace</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>username</TD> <TD>user name</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>zeros</TD> <TD>zeroes</TD> <TD>
</TD> </TR> </TABLE>
The following table lists some terms to avoid using in man pages, along with some suggested alternatives, mainly to ensure consistency across pages.
<TABLE> <TR VALIGN="top| <TD>Avoid</TD> <TD>Use instead</TD> <TD>Notes
</TD> </TR> <TR VALIGN="top| <TD></TD> </TR> <TR VALIGN="top| <TD>32bit</TD> <TD>32-bit</TD> <TD>same for 8-bit, 16-bit, etc.
</TD> </TR> <TR VALIGN="top| <TD>current process</TD> <TD>calling process</TD> <TD>A common mistake made by kernel programmers when writing man pages
</TD> </TR> <TR VALIGN="top| <TD>manpage</TD> <TD>man page, manual page</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>minus infinity</TD> <TD>negative infinity</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>non-root</TD> <TD>unprivileged user</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>non-superuser</TD> <TD>unprivileged user</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>nonprivileged</TD> <TD>unprivileged</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>OS</TD> <TD>operating system</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>plus infinity</TD> <TD>positive infinity</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>pty</TD> <TD>pseudoterminal</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>tty</TD> <TD>terminal</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>Unices</TD> <TD>UNIX systems</TD> <TD>
</TD> </TR> <TR VALIGN="top| <TD>Unixes</TD> <TD>UNIX systems</TD> <TD>
</TD> </TR> </TABLE>
Use the correct spelling and case for trademarks. The following is a list of the correct spellings of various relevant trademarks that are sometimes misspelled:
A null pointer is a pointer that points to nothing, and is normally indicated by the constant NULL. On the other hand, NUL is the null byte, a byte with the value 0, represented in C via the character constant \0.
The preferred term for the pointer is "null pointer" or simply "NULL"; avoid writing "NULL pointer".
The preferred term for the byte is "null byte". Avoid writing "NUL", since it is too easily confused with "NULL". Avoid also the terms "zero byte" and "null character". The byte that terminates a C string should be described as "the terminating null byte"; strings may be described as "null-terminated", but avoid the use of "NUL-terminated".
In general, the use of abbreviations such as "e.g.", "i.e.", "etc.", "a.k.a." should be avoided, in favor of suitable full wordings ("for example", "that is", "and so on", "also known as").
The only place where such abbreviations may be acceptable is in short parenthetical asides (e.g., like this one).
The way to write an em-dash---the glyph that appears at either end of this subphrase---in *roff is with the macro "\(em". (On an ASCII terminal, an em-dash typically renders as two hyphens, but in other typographical contexts it renders as a long dash.) Em-dashes should be written without surrounding spaces.
Compound terms should be hyphenated when used attributively (i.e., to qualify a following noun). Some examples:
The general tendency in modern English is not to hyphenate after prefixes such as "multi", "non", "pre", "re", "sub", and so on. Manual pages should generally follow this rule when these prefixes are used in natural English constructions with simple suffixes. The following list gives some examples of the preferred forms:
Hyphens should be retained when the prefixes are used in nonstandard English words, with trademarks, proper nouns, acronyms, or compound terms. Some examples:
Where a real minus character is required (e.g., for numbers such as -1, or when writing options that have a leading dash, such as in ls -l), use the following form in the man page source:
To produce single quotes that render well in both ASCII and UTF-8, use the following form for character constants in the man page source:
Manual pages may include example programs demonstrating how to use a system call or library function. However, note the following:
Avoid using the following forms to terminate a program:
.SS Program source
Always do this if the explanatory text includes a shell session log.
If you include a shell session log demonstrating the use of a program or other system feature:
This page is part of release 3.74 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at http://www.kernel.org/doc/man-pages/.
Tutoriais de Tecnologia Web