Is it safe to parse a /proc/ file?

后端 未结 7 1375
终归单人心
终归单人心 2020-12-12 09:53

I want to parse /proc/net/tcp/, but is it safe?

How should I open and read files from /proc/ and not be afraid, that some other process (o

相关标签:
7条回答
  • 2020-12-12 10:56

    The procfs API in the Linux kernel provides an interface to make sure that reads return consistent data. Read the comments in __proc_file_read. Item 1) in the big comment block explains this interface.

    That being said, it is of course up to the implementation of a specific proc file to use this interface correctly to make sure its returned data is consistent. So, to answer your question: no, the kernel does not guarantee consistency of the proc files during a read but it provides the means for the implementations of those files to provide consistency.

    0 讨论(0)
提交回复
热议问题