标准C库和系统调用如何协同工作? [英] How do the standard C library and system calls work together?

查看:234
本文介绍了标准C库和系统调用如何协同工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近对编译器,标准库和内核的内部工作感兴趣。当我在寻找标准C库的源代码时,我遇到了Glibc。但是它在Glibc的官方网站上说的是:定义系统调用和其他基本设施的库,如open,malloc,printf,exit ...

I recently got interested about inner workings of compilers, standard libraries and kernels. While I was searching for the source code of the standard C library, I came across with Glibc. But what it says in Glibc's official website is: the library which defines the ''system calls'' and other basic facilities such as open, malloc, printf, exit...

所以我想Glibc实际上不提供标准C库的源代码,而是提供了对这些函数的系统调用,然后内核小心他们,我是对的吗?

So I guess that Glibc actually doesn't provide the source code of the standard C library, but instead provides the system calls for those functions, and then the kernel takes care of them, am I right?

我想详细了解这些事情。例如, sin printf strlen ,函数在C程序中执行?如果Glibc只提供系统调用,那些函数的实际源代码在哪里?内核如何执行它们?在哪里可以找到执行这些函数的内核部分的源代码?

I would like to learn more about those things. For example, how do the sin, printf, and strlen, functions get executed in C programs? If Glibc provides just the system calls, where are the actual source codes of those functions? How does the kernel execute them? Where can be found the source code of the part of the kernel that executes those functions?

推荐答案

C库是一个用户库

系统调用是由内核提供的接口。
它们与C标准无关。它们是特定于操作系统的。
在类似UNIX的操作系统之间存在一些相似之处,但这是一个不同的主题。

The System Calls are an interface provided by the kernel. They have nothing to do with the C standard. They are OS specific. Some similarities exist between UNIX-like operating systems but that's a different topic.

在C库中实现的一些功能将终止调用系统调用一种方式或另一种方式。但是这与其他任何库都一样。

Some of the functions implemented in the C library will end-up calling a system call one way or another. But that's just the same with any other library.

我建议从OpenBSD查看C库。 Android手机也使用它。
它简单明了,文档很好。您可以在这里找到它。

I recommend looking at the C library from OpenBSD. Android phones use it as well. It's simple and clear and very well documented. You can find it here.

这篇关于标准C库和系统调用如何协同工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆