Search code examples
kerneldevice-driverfreebsd

how to programmatically make a function opened by exactly one process?


I have a device driver and I want it to be opened by only one process exactly. What structures do I have to use to actually set this property? Freebsd OS, C language, Kernel Device drivers Any tips on it?


Solution

  • You could track this inside your device driver; and reject the open. I.e. do some book keeping (is_open=true on open, is_open=false on close/loss).

    Or you could simply use the normal locking semantics of open() itself - if needed in conjunction with exclusive mode and/or fcntl/flock.