问题
As we know there is some process which is faster than other. But I always wonder Why proc process faster than others?
回答1:
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 fclose
ing it. See this.
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.
Try also cat /proc/$$/status
and cat /proc/self/maps
in some terminal, and think a bit to understand the output.
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).
来源:https://stackoverflow.com/questions/47069729/why-proc-process-faster-than-others