Search code examples
linuxdevice-driver

May I open my own device driver twice simultaneously from a user program under Linux?


Somewhere I read that opening the same file twice has an undefined semantics and should be avoided. In my situation I would like to open my own device multiple times associating multiple file descriptors to it. The file operations of my device are all safe. Is there some part of Linux between the sys call open() and the point it calls the registered file operation .open() that is unsafe?


Solution

  • It is perfectly fine to open the same device file twice, as long as your driver is ok with that. There is no hidden part that would make it unsafe if it is safe in the kernel.

    For example, some video application use one process to do the display or capture, while another opens the device file to handle the controls.

    If the driver does not support multiple open, then it should return an error when a second open happens.