Chinaunix首页 | 论坛 | 博客
  • 博客访问: 300346
  • 博文数量: 35
  • 博客积分: 836
  • 博客等级: 准尉
  • 技术积分: 678
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-07 20:11
文章分类

全部博文(35)

文章存档

2013年(1)

2012年(24)

2011年(10)

分类: LINUX

2011-11-17 22:21:39

今天工作的时候突然想到这个manpage的实现原理。然后找了一些资料,做了一些实验。记录如下。

 

使用linux写代码也好,工作也好,最爽的莫过于使用manpage,然后做些小实验理解函数及相关命令行的应用方式。省去了baidu,google的时间。

 

Linux manpage分为以下9类:

1 User commands that may be started by everyone. 2 System calls, that is, functions provided by the kernel. 3 Subroutines, that is, library functions. 4 Devices, that is, special files in the /dev directory. 5 File format descriptions, e.g. /etc/passwd. 6 Games, self-explanatory. 7 Miscellaneous, e.g. macro packages, conventions. 8 System administration tools that only root can execute. 9 Another (Linux specific) place for kernel routine documentation.

 

相应类别的manpage就在相应的目录下。而整个man的路径则是由MANPATH来指定。另外man的实现会有相应的配置文件,其中会有一些默认的配置项。man的配置文件在/etc文件中,ubuntu中为/etc/manpath.config其中定义了默认的man路径。当用户执行相应的man应用时会从指定的MANPATH去寻找相应的manpage文件。

 

在MANPATH路径下会有man1, man2…类似的文件夹,其中保存同一类型的manpage。当用户输入的请求与其中的文件名对应上时则映射成功,显示给用户输出。

 

例如,man ls, 在我的电脑上就会映射到/usr/share/man/man1/ls.1.gz。然后man解析manpage内容输出到term中。

 

其中manpage还有自己的一些格式,没有具体研究过。使用可以参考google。

 

自己做了个实验

#pwd

#/usr/share/man/man2

#gunzip mmap.2.gz

#mv mmap.2 test_sysctl.2

#man test_sysctl

屏幕输出mmap的manpage。

修改test_sysctl.2文件内容后,再man test_sysctl,显示内容随之改变。

 

不在同一个机器上搞的实验,不容易截图,不太爽……

 

参考资料:

阅读(2516) | 评论(0) | 转发(0) |
0

上一篇:终结

下一篇:想吐

给主人留下些什么吧!~~