In this source code http://man7.org/tlpi/code/online/dist/sysinfo/procfs_pidmax.c.html the file /proc/sys/kernel/pid_max
is first simply read (using the read
syscall) and then simply written (using the write
syscall).
Why is it no necessary to lseek
to the beginning before writing? I thought the file-offset pointer is the same for read's and write's (that's what the author of the associated books says).
This is because of
/proc
is not real file system sopid_max
writes are handled in a way you don't need anyseek
. I even don't know if seeks are supported here.Just to give you feeling of how different
/proc
files are here is reference for pretty old but illustrative kernel bug specially related topid_max
: https://bugzilla.kernel.org/show_bug.cgi?id=13090This link should explain you even more details: T H E /proc F I L E S Y S T E M
And finally developerWorks article "Access the Linux kernel using the /proc filesystem" with step-by-step illustration of kernel module code which have /proc FS API. This looks like 100% what you need.