Search code examples
linux-kernelforklinux-device-driver

How are kernel states duplicated on a fork?


Suppose I have a character device driver in Linux that allocates some memory in the kernel to store some state against every open file descriptor.

Some process opens a fd on the driver and through some ioctls the process also has provided initialization parameters for this state.

Now the process forks. All the file descriptors will also be created for the child process.

How will the fd specific state be duplicated? AFAIK do_fork only duplicates the data structure the kernel knows about.

Will the child process have to re-initialize the fd or it will end up sharing the state with the parent process?


Solution

  • No open file description state is duplicated on fork or dup. All such state will be shared between parent and child.