I am following an example FUSE Tutorial to understand how FUSE works in linux. In the example all the dynamic data is allocated using malloc, and passed in as user data to the fuse_main
function. This data is later accessible for any fuse calls. These calls need not be from the same process. How does this work?
To make the question more clear ,
i run the main bbfs
program with ../src/bbfs rootdir mountdir
to mount the file system. It is in the main() of bbfs.c that the malloc is called. The bbfs program also defines several fuse function calls. But this program exits after the filesystem is mounted.
How can other programs(or the kernel) which calls read()
or open()
on the mounted filesystem
1.access the memory allocated using malloc by the bbfs program if it has already exited? Wouldn't the OS free up the memory allocated using malloc after the program bbfs
exited?
2.access the defined functions, if the process that defined them had already exited? Where would the object code
of the fuse functions reside after the process exited?
I am a bit confused about the lifetimes of the object code and the heap memory objects here and how other programs (or the kernel) use it later. Any help or pointers would be appreciated.
Most of your question is based on a false assumption:
It's not actually exiting at all. It's forking into the background and continuing to run as long as the filesystem is mounted.
While it's running, everything works as normal.