Вопрос

If I open a dynamic library using dlopen and my program terminates without a corresponding dlclose, will the reference count be decremented? If not, what happens? Will the library remain loaded until the next reboot?

Это было полезно?

Решение

Dynamic loader is a user-space code (ld.so.1 in linux/glibc). It is loaded into userspace of the program you are running, and doesn't interact with other processes. So there is no global reference counters.

There is, however, a way to share code of dynamic libraries between processes. Dynamic loader uses mmap() to load library code in process memory. mmap-ed data of the same library will be shared between all processes that use it (until they write anything to these data pages, this will create their own copy of data using COW). And when your program terminates, all mmap-ed regions are freed. You may consider this a kind of reference counter decrement - your copies of data pages are now released.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top