fork()

create new process 

Function


SYNOPSIS

#include <unistd.h>

pid_t fork(void);


DESCRIPTION

The fork() function creates a new process. The new process (the child process) is an exact copy of the calling process (the parent process). The child process inherits the following attributes from the parent process:

The child process differs from the parent process in the following ways:

The new process has a single thread. If a multi-threaded process calls fork(), the new process contains a replica of the calling thread and its entire address space, including the states of mutexes and other resources. Consequently, to avoid errors, the child process may only execute async-signal safe operations until such time as one of the exec() functions is called. Fork handlers may be established using the pthread_atfork() function to maintain application invariants across fork() calls.


PARAMETERS

None.


RETURN VALUES

If successful, fork() returns 0 in the child process, and returns the process ID of the child process to the parent process. On failure, it returns -1 and sets errno to one of the following values:

EAGAIN 

The system lacked the necessary resources to create another process, or the system-imposed limit on the total number of processes under execution system-wide would be exceeded.

The process calling fork() is not a NuTCRACKER Platform process.

ENOSYS 

fork() was called inside the child of a vfork() operation.


CONFORMANCE

UNIX 98, with exceptions.


MULTITHREAD SAFETY LEVEL

Async-signal-safe, with exceptions.

This function is only Async-signal-safe on Windows NT, not on Windows 9x.


PORTING ISSUES

The Windows process model differs considerably from the UNIX process model. The NuTCRACKER Platform implements fork() using the available Win32 process operations, and must perform the address space replication. The returned process ID is the Win32 process ID. Refer to Process Management in the Windows Concepts chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for a detailed discussion of the process model.

You may not call fork() from a non-NuTCRACKER Platform application (for example, from a standalone NuTCRACKER Platform DLL used in a native Win32 application). Refer to Building Standalone DLLs in the Porting Shared Libraries chapter of the PTC MKS Toolkit UNIX to Windows Porting Guide for more information.

You may not call fork() from the child of a vfork() operation.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
alarm(), execl(), execle(), execlp(), execlpe(), execv(), execve(), execvp(), execvpe(), mmap(), pthread_atfork(), semop(), setitimer(), setpriority(), shmat(), signal(), times(), umask(), vfork()


PTC MKS Toolkit 9.6 patch 1 Documentation Build 5.