HPlogo MPE/iX Developer's Kit Reference Manual Volume I: HP 3000 MPE/iX Computer Systems > Chapter 4  POSIX/iX Library Function Descriptions

fork

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Creates a new child process.

Syntax

   #include <sys/types.h>

   #include <unistd.h> 

   pid_t fork (void);

Parameters

None.

Return Values

>0

Success. The process ID of the newly created child process is returned to the calling process.

0

Success. A value of 0 is returned to the newly created child process.

-1

An error occurred. The process is not created, and errno is set to indicate the error condition.

Description

The fork() function creates a new child process. Both the new child process and the calling process (known as the parent process) continue execution upon the return from fork(). The new process is an exact copy of the calling process with the following exceptions:

  • The child process has a unique process ID that does not match any active process group ID.

  • The child process's parent process ID is that of the calling process.

  • The child process has its own copy of the parent's file descriptors. Each of the child's file descriptors refers to the same open file description as the corresponding file descriptor of the parent.

  • The child process has its own copy of the parent's open directory streams. Each open directory stream in the child process shares stream positioning with the corresponding directory stream of the parent.

  • Directory streams are implemented using file descriptors. Both parent and child share the same open file descriptor for each directory stream.

  • The child process's tms_utime, tms_stime, tms_cutime, and tms_cstime are set to zero.

  • File locks set by the parent process are not inherited by the child process.

  • Pending alarms are cleared for the child process.

  • The set of signals pending for the child process is set to the empty set.

Implementation Considerations

Refer to the EPERM and EIMPL error descriptions below.

Some MPE/iX process characteristics not defined by POSIX are not inherited by the child. Examples are CM structures such as extra data segments, RINs, and SIRs.

The following MPE/iX characteristics not defined by POSIX.1 are inherited by the child:

  • process's priority

  • process's capability

  • stack size

  • heap size

Errors

If an error occurs, errno is set to one of the following values:

EAGAINCAUSEThe system lacked the resources to create another process.
 ACTIONAttempt process creation at a later time, or decrease the number of processes associated with the application.
EFAULTCAUSEThe system detected a NULL or bad address in attempting to use the functional return argument.
 ACTIONMake sure that the functional return is correctly initialized.
EIMPLCAUSEThe stack and heap could not be copied to the new process, or a file could not be inherited to the new process, or a system data structure could not be copied to the new process.
 ACTIONContact your Hewlett-Packard Support Representative.
ENOMEMCAUSEThe program requires more memory than the system allows for a process.
 ACTIONReduce memory requirements for the process.
EPERMCAUSE

One of the following:

  • The calling process does not have the MPE/iX process handling (PH) capability.

  • The calling process is not executing a program file whose MPE/iX file code is NMPRG.

  • The calling process has outstanding switches to CM code, has set critical mode, has outstanding NOWAITIO, or is holding an operating system internal resource.

 ACTION

One of the following:

  • Make sure that the calling process has the MPE/iX PH capability.

  • Make sure that the calling process is executing a program file whose file code is NMPRG.

  • Do not execute fork() when the calling process has outstanding switches to CM code, has set critical mode, has outstanding NOWAITIO, or is holding an operating system internal resource.

See Also

alarm(), execl(), execv(), kill(), wait(), POSIX.1 (Section 3.1.1)

Feedback to webmaster