用于 unix/linux 开发的标准 I/O 库或底层 [英] standard I/O library or Low-Level for unix / linux development

查看:26
本文介绍了用于 unix/linux 开发的标准 I/O 库或底层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在复习 unix 调用,所以这似乎是一个幼稚的问题(在假期和无聊时).我知道 C 中有标准的 i/o,但似乎低级调用(写入、读取、打开)在实践中用于类 UNIX 系统(刚刚检查了几个开源项目).标准io在实践中使用的多吗?是否有更多使用低级api的截止日期或特定原因?或者我是否从一些精选的案例中做出了一个关于低级别更受欢迎的错误假设?我知道标准 i/o 是一种 C 语言元素,但似乎它们实现了相同的目标,并且更多地使用了低级.

I'm brushing up on unix calls so this might seem a naive question (on vacation and just bored). I know that there's standard i/o in C but it always seems like the low-level calls (write, read, open) are used in practice for UNIX-like systems(just checked a couple of open-source projects). Is standard-io used in practice much? Are there cutoffs or specific reasons why the low-level api is used more? Or am I making a bad assumption from a few cherry-picked cases regarding low-level being more popular? I understand standard i/o is a C language element but seems like they achieve same thing and that low-level is used more.

推荐答案

stdio(3) 库没有涵盖 Linux 上可用的所有功能.特别是 socket(2) 和其他低级功能(例如,使用 poll(2) 等进行轮询...) 是 函数不提供.但是, 函数通常会提供 buffering出于性能原因,实际上非常重要.因此,为每个字节调用 write(2) 将非常低效.使用 fflush(3) 来刷新 <stdio.h> 缓冲区.

The stdio(3) library don't cover all the abilities available on Linux. In particular, socket(2) and other low level functionalities (e.g. polling with poll(2) etc...) is not provided by <stdio.h> functions. However, <stdio.h> functions usually give buffering which is practically very important for performance reasons. So calling write(2) for every single byte would be very inefficient. Use fflush(3) to flush <stdio.h> buffers.

阅读高级 Linux 编程了解更多信息.

在实践中,混合 函数和低级系统调用(如 read(2), write(2), mmap(2)民意调查(2)fcntl(2) ...) 与 ; 函数通常(但并非总是)不切实际.另请参阅fileno(3).所以人们可能会选择在系统调用级别进行编码.

In practice, mixing <stdio.h> functions and low-level syscalls (like read(2), write(2), mmap(2), poll(2), fcntl(2) ...) with <stdio.h> functions is often (but not always) impractical. See also fileno(3). So people may choose to code at the syscall level.

但是,当 函数足够用时,使用起来也很方便.

However, when  <stdio.h> functions are enough it is convenient to use them.

此外 C11 标准,但 write 等...仅在 POSIX ....

Also <stdio.h> is standardized in the C11 standard, but write etc... only in POSIX ....

这篇关于用于 unix/linux 开发的标准 I/O 库或底层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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