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 loaded. Am I wrong?
+6
A:
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.
caf
2010-10-04 13:00:46
+2
A:
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.
MarkR
2010-10-04 14:36:30