Writing and reading to the linux / proc / ... file system without lseek ()

In this source code, http://man7.org/tlpi/code/online/dist/sysinfo/procfs_pidmax.c.html the file /proc/sys/kernel/pid_max first simply read (using syscall read ) and then simply written ( using write syscall).

Why is there no need for lseek before writing? I thought the file offset pointer is the same for reading and writing (this is what the author of related books says).

+7
c linux file read-write lseek
source share
2 answers

This is because /proc not a real file system, so pid_max entries pid_max processed in such a way that you don't need seek . I don’t even know if searches are supported here.

Just to give you an idea of ​​how the different /proc files here relate to a rather old but illustrative kernel bug specifically related to pid_max : https://bugzilla.kernel.org/show_bug.cgi?id=13090

This link should explain you even more detailed information: THE / proc F I LESYSTEM

Finally, the developerWorks article, “Accessing the Linux kernel using the / proc file system,” illustrates step-by-step illustration of the kernel module code that has the / proc FS API. This is like 100% what you need.

+6
source share

I looked at the kernel source, the files under / proc / sys / are under the control of the sysctl table, the read / write callbacks for each offset of the write support file. The pid_max entry has a single int value for operation, and therefore, the offset in these callbacks is not actually used.

+1
source share

All Articles