1

How does the Linux kernel handle multiple reads/writes to procfs? For instance, if two processes write to procfs at once, is one process queued (i.e. a kernel trap actually blocks one of the processes), or is there a kernel thread running for each core?

The concern is if you have a buffer used within a function (static to the global space), do you have to protect it or will the code be run sequentially?

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
reza
  • 1,188
  • 3
  • 17
  • 32
  • I would look at existing kernel code for procfs, and do likewise. – Basile Starynkevitch Oct 12 '12 at 16:24
  • 2
    Pretty sure the procfs callbacks happen in the context of the reading/writing process. There is no handler thread or queueing involved. If you want synchronization you have to do it yourself. – Andy Ross Oct 12 '12 at 17:04

1 Answers1

0

It depends on each and every procfs file implementation. No one can even give you a definite answer because each driver can implement its own procfs folder and files (you didn't specify any specific files. Quick browsing in http://lxr.free-electrons.com/source/fs/proc/ shows that some files do use locks).

In either way you can't use the global buffer because a context switch can always occur, if not in the kernel then it can catch your reader thread right after it finishes the read syscall and before it started to process the read data.

Eytan Naim
  • 159
  • 14