为什么proc处理速度比别人快? [英] Why proc process faster than others?

查看:51
本文介绍了为什么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处理速度比别人快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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