Static linking and memory usage

David Schwartz
Tue, 14 Aug 2007 22:07:46 -0000

> If I have an executable which is staticly linked with many copies
> of it running (a CGI script in fact), will all those copies share
> the text segment of the executable on the disc, or will it actually
> use up real memory resource with many copies of the executable ? I
> have been assuming the former, but possibly that is not correct.

As is the case for all files, if the contents are not modified, the physical
memory is shared. Two or more processes can map the same page of the same
file and will get the same physical page of memory, normally marked
unshare/copy-on-write.

DS