Reputation: 411
Is it possible to read content of /proc/[pid]/ files through binary struct without parsing text data?
Upvotes: 0
Views: 235
Reputation: 13065
No. You don't want this.
First, the internal structs in the kernel change all the time. (For example, processes can have multiple PIDs when running LXC, some things change from 32 bits to 64 bits on different kernels, etc) You probably don't want your program to randomly break. That's why they dump the data to a more friendly format.
Second, if you are looking for performance, the time converting to/from text is probably small compared to the overhead of context switching to the kernel. Things like Sar
and atop
manage just fine using the existing interfaces, and nobody complains they are slow.
If you really need speed (why?), then write your own module to dump the data in your own binary format, or just tap into the existing tracing mechanisims.
Upvotes: 1