为什么proc处理速度比别人快?

编程入门 行业动态 更新时间:2024-10-27 20:36:21
本文介绍了为什么proc处理速度比别人快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们知道有些过程比其他过程快.但是我总是想知道为什么proc处理程序比其他程序更快?

As we know there is some process which is faster than other. But I always wonder Why proc process faster than others?

推荐答案

混乱./proc/文件系统(阅读 proc(5))的确是一个伪文件系统,在任何硬盘上都没有真实文件.因此,读取速度很快(可能比读取正在旋转的硬盘上的文件要快).例如,您可以编写一些C代码 fopen -ing /proc/self/maps ,使用 fgets 在每一行上循环,然后显示该行在您的 stdout 上,最后 fclose 将其关闭.参见此.

Confusion. The /proc/ file system (read proc(5)) is indeed a pseudo-file system without real files on any hard disk. So reading it is quick (and could be faster than reading a file on a spinning hard disk). For example you could write some C code fopen-ing /proc/self/maps, looping on every line using fgets, and showing that line on your stdout, and finally fcloseing it. See this.

在Linux上,/proc/是查询内核有关操作系统状态的便捷方法.通常,您会从中读取(而不是写入)伪文件.

On Linux /proc/ is a convenient way to query the kernel about the operating system's state. You generally read (not write) pseudo-files from it.

在某些终端中也尝试 cat/proc/$$/status 和 cat/proc/self/maps ,并花点时间来理解输出.

Try also cat /proc/$$/status and cat /proc/self/maps in some terminal, and think a bit to understand the output.

顺便说一句,如果您想对合理大小的文件快速执行一些IO,请将它们放在一些 tmpfs上文件系统(该文件系统在关闭时会丢失,并且有一些限制).

BTW, if you want to do quickly some IO on files of reasonable size, put them on some tmpfs filesystem (which would be lost at shutdown time, and has some limitations).

更多推荐

为什么proc处理速度比别人快?

本文发布于:2023-10-18 11:40:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504126.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:速度   proc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!