I am writing a program consisting of user program and a kernel module. The kernel module needs to gather data that it will then "send" to the user program. This has to be done via a /proc file. Now, I create the file, everything is fine, and spent ages reading the internet for answer and still cannot find one. How do you read/write a /proc file from the kernel space ? The write_proc and read_proc supplied to the procfile are used to read and write data from USER space, whereas I need the module to be able to write the /proc file itself.
The source code is stored in a file named mainc. c within the /init directory. The code initializes the kernel and some initial processes.
create_proc_entry() Both of these functions are defined in the file linux/proc_fs. h. The create_proc_entry is a generic function that allows to create both read as well as write entries. create_proc_read_entry is a function specific to create only read entries.
That's not how it works. When a userspace program opens the files, they are generated on the fly on a case-by-case basis. Most of them are readonly and generated by a common mechanism:
You (from the kernel) do not "write" to procfs files, you supply the results dynamically when userspace requests them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With