Open System Services Programmer's Guide

Process Creation Functions
You can create OSS processes with the fork() function. The attributes of the parent process are
propagated to the child process, and the child process has an OSS process ID that uniquely
identifies it. An OSS process can send signals to and receive signals from other OSS processes.
You can query and modify the process environment using functions such as getpid() and
putenv(). OSS processes receive notification when a child process terminates with the SIGCHLD
signal and can use the wait() and waitpid() functions.
Beginning with the H06.24 and J06.13 RVUs, you can create 64-bit OSS processes. For information
about 64-bit OSS processes, see “64-Bit OSS Processes” (page 286).
Example 26 (page 107) and Example 27 (page 110) illustrate typical use of the fork(), execv(),
and wait() functions in an application. These programs demonstrate one of the restrictions of
using a member of the standard exec set of functions: you are limited to launching new processes
in the same processor; refer to “Performance Considerations (page 138) for less restricted examples.
The launcher program in Example 26 is compiled as a linked program file named dlaunchl.
The server program in Example 27 is compiled as a linked program file named dserver. (A
requester program, shown in Example 44 (page 182), is also compiled as a linked program file
named requester2.) All programs are secured for execution in the current working directory.
NOTE: These examples use the AF_INET sockets functions, which provide an interface to HP
NonStop TCP/IP. The programs could also be written using the AF_INET6 sockets functions to
interface to HP NonStop TCP/IPv6. For information and examples of AF_INET6 sockets usage,
refer to the TCP/IP Programming Manual.
In this application, dlaunch1 creates an AF_INET socket and listens for incoming connections
from one or more copies of requester2. Upon receipt of a connection, dlaunch1 uses fork()
to create a duplicate of itself as a child process.
The child process duplicates itself again with another call to fork() to create a grandchild. The
grandchild overwrites itself by starting server, using an execv() call. The child process exits
immediately so that the dlaunch1 call to the wait() function prevents the child process from
becoming a zombie process and wasting processor resources.
106 Managing Processes