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

HP-UX Handbook Rev 13.00 Page 27 (of 101)
Chapter 11 Software Development
October 29, 2013
If there were no more libraries to load, but there were still symbols that could not be bound to an
address (could not be resolved), an error would be reported and the program would abort.
Execute main()
After the libraries are loaded and all symbols could be resolved, main() is called to execute the
code the program was written for. HelloWorld was written to print the text "Hello World!". The
required system calls are:
ioctl(1, TCGETA, 0x7dff0f30) ..................... = 0
Hello World!
write(1, "H e l l o W o r l d ! \n", 13) ....... = 13
In general, ioctl() inquires or changes the status of a file, and write() sends data to a file. On
Unix, every input or output channel is treated as a file, and processes refer to files via file
descriptors which are indices for the file table of the process. The first three entries are preset:
Number
Name
Description
0
stdin
The standard input channel
1
stdout
The standard output channel
2
stderr
The error output channel
So both system calls operate on stdout. The text appears on stdout before the system call is
printed by tusc, because system calls are logged near the end of the call, when its return code is
available.
Threads
In the classic view of process management, a process is an entity that executes program code and
has its own private address space. As a consequence, if the program is waiting for some system
resource, e.g. disk or network I/O, it can't do anything else. The process is sent to sleep by the
system, and waken up again if the resource becomes available. Also, it cannot benefit from a
multiprocessor system, because each process can only run on one CPU. To use multiple CPU’s,
multiple processes are needed.
To increase the performance of a single process, the threads model was introduced with HP-UX
10.X. Since then, a process is only a container. Program execution is done now by one or more
threads. Each thread has its own instructions to execute and shares process resources with the
other threads. Now, if one thread is waiting for system resources, another thread can be executed,
and the process is not forced to be idle.