scdmb
scdmb

Reputation: 15611

Sharing shared object between multiple processes

Are shared objects separately loaded for each process or one shared object is shared among them? For example, let's say that some program uses libc.so. Then two processes of this program are launched. Will be this shared object loaded TWO times for each process in their memory area OR will it be loaded somewhere in memory ONCE and mapped in memory of two processes?

Upvotes: 2

Views: 1673

Answers (2)

ninjalj
ninjalj

Reputation: 43688

Shared objects are loaded via mmap() with the MAP_PRIVATE flag. This means that these are copy-on-write mappings, they initially point to the same memory, but once any of them is modified, it is copied and "unshared" before the modification.

Upvotes: 2

Dominik G
Dominik G

Reputation: 614

Check this thread. In theory each process holds each it's own address space, and threads should be used for such purpose, but it's a matter of system implementation.

Upvotes: 0

Related Questions