手册页:如何使用参数

时间:2013-09-19 19:50:02

标签: c++ c man

最终,我希望能够知道如何使用功能,而无需在线查找示例。

例如,如果我man 2 mkfifo,则会显示:

NAME
     mkfifo -- make a fifo file

SYNOPSIS
     #include <sys/types.h>
     #include <sys/stat.h>

     int
     mkfifo(const char *path, mode_t mode);

DESCRIPTION
     Mkfifo() creates a new fifo file with name path.  The access permissions are specified by mode and restricted by the umask(2) of the calling process.

     The fifo's owner ID is set to the process's effective user ID.  The fifo's group ID is set to that of the parent directory in which it is created.

const char *path非常不言自明,我可以毫不费力地使用该参数调用mkfifo函数,但我更关心的是mode_t参数。手册页给出了一个关于模式用途的小解释,但没有解释如何使用它以便用它调用函数。

有没有办法浏览手册页来理解这些论点?

我尝试man mode_tman mode,但没有任何结果。

2 个答案:

答案 0 :(得分:1)

该手册页假设您熟悉其他的地方,当它说:

时会使用模式标记
  

它以通常的方式由进程的umask修改:创建的文件的权限是(mode&amp; ~umask)。

但是,如果您浏览“另请参阅”部分中的每个页面:

  

另请参阅

     

mkfifo(1),close(2),open(2),read(2),stat(2),umask(2),write(2),mkfifoat(3),fifo(7)

你最终会打开(2),它提供了你可以使用的模式的详尽列表。也就是说,您使用man 2 open访问的手册页包括(在描述标志时):

  

O_CREAT   如果该文件不存在,则将创建该文件。文件的所有者(用户ID)设置为进程的有效用户ID。组所有权(组ID)设置为进程的有效组ID或父目录的组ID(取决于文件系统类型和装入选项以及父目录的模式,请参阅装入选项bsdgroups和mount(8)中描述的sysvgroups。

     

模式指定在创建新文件时使用的权限。当在flags中指定O_CREAT时,必须提供此参数;如果未指定O_CREAT,则忽略模式。进程的umask以通常的方式修改有效权限:创建的文件的权限是(mode&amp; ~umask)。请注意,此模式仅适用于将来访问新创建的文件;创建只读文件的open()调用可能会返回一个读/写文件描述符。

     

为模式提供以下符号常量:...

您可能会发现另一种有用的方法是搜索有关手册页指定的包含的信息。例如,Google sys/types.hsys/stat.h的Google搜索结果显示:

我意识到这并不排除必须“在线查找示例”。某些系统可能包含标题的手册页,但其他系统可能不包括。

答案 1 :(得分:1)

您要求的内容已经存在,它是命令info。尝试:

info mkfifo

你会得到这样的东西:

 -- Function: int mkfifo (const char *FILENAME, mode_t MODE)
     The `mkfifo' function makes a FIFO special file with name
     FILENAME.  The MODE argument is used to set the file's
     permissions; see *note Setting Permissions::.

如果将光标移到*note Setting Permissions::.位并按ENTER,您将进入umask页面,其中包含更详细的文件权限说明。

此外,当只有给定主题的手册页可用时,info可以读取手册页。简而言之,您再也不必使用man