Not knowing the /proc file system
The Linux /proc "file system" is kernel to user space communication hammered into the wrong form because "everything is a file". /proc is a system call with a fake file system API, and this matters.<p>The sample code won't work reliably, because it assumes that the "files" won't change while being read. If you read /proc, you must "read" each file with one unbuffered kernel read to be free of race conditions. See [1].<p>The Linux kernel has no standard mechanism for delivering a variable-sized result from a system call. I/O comes closest to that, so this was hammered into the file system API. The dents show. /proc does not have standard file semantics.<p>[1] <a href="https://stackoverflow.com/questions/5713451/is-it-safe-to-parse-a-proc-file" rel="nofollow noreferrer">https://stackoverflow.com/questions/5713451/is-it-safe-to-pa...</a>