HP-UX HB v13.00 Ch-11 - Software Development

HP-UX Handbook Rev 13.00 Page 23 (of 101)
Chapter 11 Software Development
October 29, 2013
Load the Program
Starting a program usually consists of two steps. First, a new process is created. This is called
forking. The new process is called the child, the other one is the parent process. After forking,
both processes are identical except of the process ID (PID), which must be unique on the whole
system. In a second step the new program is loaded and executed in the child process, thus
replacing the old one which was a copy of the program in the parent process. Afterwards the old
program continues running in the parent process, and the new program running in the child
process:
process A
program X
fork()
process A
program X
process B
program X
exec()
process B
program Y
The tusc output shows:
execve("./HelloWorld", 0x87fffffffffff5b0, 0x87fffffffffff5c0) = 0 [32-bit]
execve() loads and starts our HelloWorld program, after tusc forked a new process. The
fork() system call is not in the trace because it is executed inside of tusc. execve() takes 3
arguments, the path to the program file, the argument list and the environment.
A new program can also be executed without prior forking. In this case, the program that calls
execve() to start the new program, will cease to exist afterwards.
Load Shared Libraries
Every shared library is loaded in the same way. It is mapped into memory using mmap(2). To be
more precise, several pieces of the shared library file are copied into memory. There are at least
two pieces for each library:
The code section is mapped shared, to allow multiple loadings of this library to use the
already mapped instance, rather than to map it again, in the same or even another process.
The data section is mapped private, which means each process that uses this shared
library gets its own copy of the data part, to not conflict with other processes.
Sharing libraries between multiple processes saves a lot of memory, because the code contained
in a shared library only needs to exist and to be loaded once, no matter how many processes load
it.