免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1698 | 回复: 8
打印 上一主题 下一主题

man 2部分的系统调用和操作系统内核所说的系统调用一样吗 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-09-08 08:53 |只看该作者 |倒序浏览
比如我们读一个文件可以
#include <unistd.h>
read(fildes, buf, bytes)
这个可以用man -s2 read在shell中看它的格式,我的理解是man -s2出来的都是系统调用
操作系统内核的书中也有系统调用这个词,这两个是一样的吗。还是我们一般程序用read时,也只是OS所说系统调用的一个封装,执行read要先在用户态执行,然后到内核态执行。

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2008-09-08 09:36 |只看该作者
你的理解是有不同类型的系统调用吗,内核源码提供的一般称作内核API

论坛徽章:
0
3 [报告]
发表于 2008-09-08 10:14 |只看该作者

回复 #2 Godbach 的帖子

我的意思是是不是我们一般用C语言编程时用open read write这些函数时(这个应该就叫系统调用吧)是不是就是内核API还是我们调的只是内核API的一个封装,调用内核API是库里面去调的

论坛徽章:
0
4 [报告]
发表于 2008-09-08 10:16 |只看该作者
man 2 部分的函数“应该”是系统调用,但是由于不同的操作系统实现不一样,也不一定就是系统调用。比如flock(2),在某些系统上是使用fcntl实现。flock就只是一个函数,不是系统调用。

论坛徽章:
0
5 [报告]
发表于 2008-09-08 10:23 |只看该作者
内核API
man -s2
man -s3
这三部分的关系到底是怎样的,有这方面解释的好书吗。

是不是man -s3的库函数都是用man -s2部分的函数来实现的
比如fopen内部调用open来实现。

论坛徽章:
0
6 [报告]
发表于 2008-09-08 10:27 |只看该作者
/usr/share/man : Manual pages
Purpose

This section details the organization for manual pages throughout the system, including /usr/share/man. Also refer to the section on /var/cache/man.

The primary <mandir> of the system is /usr/share/man. /usr/share/man contains manual information for commands and data under the / and /usr filesystems. [31]

Manual pages are stored in <mandir>/<locale>/man<section>/<arch>. An explanation of <mandir>, <locale>, <section>, and <arch> is given below.

A description of each section follows:

    *      man1: User programs Manual pages that describe publicly accessible commands are contained in this chapter. Most program documentation that a user will need to use is located here.
    *      man2: System calls This section describes all of the system calls (requests for the kernel to perform operations).
    *      man3: Library functions and subroutines Section 3 describes program library routines that are not direct calls to kernel services. This and chapter 2 are only really of interest to programmers.
    *      man4: Special files Section 4 describes the special files, related driver functions, and networking support available in the system. Typically, this includes the device files found in /dev and the kernel interface to networking protocol support.
    *      man5: File formats The formats for many data files are documented in the section 5. This includes various include files, program output files, and system files.
    *      man6: Games This chapter documents games, demos, and generally trivial programs. Different people have various notions about how essential this is.
    *      man7: Miscellaneous Manual pages that are difficult to classify are designated as being section 7. The troff and other text processing macro packages are found here.
    *      man8: System administration Programs used by system administrators for system operation and maintenance are documented here. Some of these programs are also occasionally useful for normal users.


这个可以么?

论坛徽章:
0
7 [报告]
发表于 2008-09-08 11:05 |只看该作者

回复 #6 benbenr 的帖子

这个解释的不详细
还是去glibc了,看它调用什么实现的

论坛徽章:
0
8 [报告]
发表于 2008-09-08 21:55 |只看该作者
你用的solaris吧,
man -s 2 intro
man -s 3 intro

里面介绍的比较详细了

通常来说,2是system call,3是library和function
至于3是不是全部都是用2来实现的。这个未必。肯定有不少function是不需要系统服务界面的。

论坛徽章:
0
9 [报告]
发表于 2008-09-08 22:25 |只看该作者
本质一样形式不一样。
man 2 所谓的系统调用是标准系统调用的C接口;内核提供原生的系统调用接口(如Linux的int80)。
glibc把原生接口封装成C接口。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP