After I have the executable file running I overwrite its .so library file with a new version and this causes the executable to die with segmentation fault. I thought the library file is being accessed only when ELF file is loa开发者_JAVA百科ded. Am I wrong?
The library file is mapped into the memory when it is loaded (usually, when the executable is loaded - but libraries can also be loaded later with dlopen()
). The actual pages of the file are then demand-loaded as required.
Overwriting the file will cause pages from the file mapped MAP_SHARED
(which is most of them) to be updated with the new contents. This is what causes the segmentation faults. Don't do that - instead, remove the existing .so file, then write the new one in its place.
Like caf said, it's not a good idea to overwrite an executable while it's running.
Instead, write the new files as a temporary file in the same directory, then rename it atomically with rename(). This is what installers typically do.
精彩评论