Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

206 Process Environment Chapter 7


stack

heap

uninitialized data
(bss)
initialized data

text

command-line arguments
and environment variables

initialized to
zerobyexec

read from
program file
byexec

high address

low address

Figure 7.6 Typical memory arrangement

Thesize( 1 ) command reports the sizes (in bytes) of the text, data, and bss
segments. For example:
$size /usr/bin/cc /bin/sh
text data bss dec hex filename
346919 3576 6680 357175 57337 /usr/bin/cc
102134 1776 11272 115182 1c1ee /bin/sh
The fourth and fifth columns arethe total of the three sizes, displayed in decimal and
hexadecimal, respectively.

7.7 Shared Librar ies


Most UNIX systems today support shared libraries. Arnold[ 1986 ]describes an early
implementation under System V,and Gingell et al. [ 1987 ] describe a different
implementation under SunOS. Shared libraries remove the common library routines
from the executable file, instead maintaining a single copy of the library routine
somewhere in memory that all processes reference. Thisreduces the size of each
executable file but may add some runtime overhead, either when the program is first
executed or the first time each shared library function is called. Another advantage of
shared libraries is that library functions can be replaced with new versions without
having to relink edit every program that uses the library (assuming that the number and
type of arguments haven’t changed).
Different systems provide different ways for a program to say that it wants to use or
not use the shared libraries. Options for thecc( 1 )andld( 1 )commands aretypical. As
Free download pdf