Search code examples
linuxlinux-kerneldriverlinux-device-driverdevice-driver

Difference between 2 process and 2 threads in contex of usage of device file ( node file )


I had made a driver(simpler one).

Now i am opening device file through 2 process (By fork()) and through 2 threads. What is the differences of them ??


Solution

  • First when I saw your question i thought that there is no difference but just increase in the fd numbers, starts from 3 and increments. Doubt is when you open the device node in main thread, you can use the same fd in the threads. When you open the device node through fork(), then also child process inherits the file descriptor. Important point is that, since thread and child process (fork()) inherits the file descriptor, if thread closes the fd then device node opened is literally closed, but in case of fork(), even though you close the inherited fd, device node is not closed since the file reference count is two in OFDT (Open File Descriptor Table) data structure not one as in the case of threads. Hope this answer clarifies your doubt :-).