fork, f_fork, and vfork: Standard C Library (libc.a)
#include <unistd.h>
pid_t fork(void)
pid_t f_fork(void)
int vfork(void)
The fork subroutine creates a new process. The new process (child process) is an almost exact copy of the calling process (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:
Attention: If you are using the fork or vfork subroutines with an Enhanced X-Windows, X Toolkit, or Motif application, open a separate display connection (socket) for the forked process. If the child process uses the same display connection as the parent, the X Server will not be able to interpret the resulting data. See the Implementation Specifics section for more information.
The f_fork subroutine is similar to fork, except for:
Upon successful completion, the fork subroutine returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the errno global variable is set to indicate the error.
The fork subroutine is unsuccessful if one or more of the following are true:
These subroutines are part of Base Operating System (BOS) Runtime.
The vfork subroutine is supported as a compatibility interface for older Berkeley Software Distribution (BSD) system programs and can be used by compiling with the Berkeley Compatibility Library (libbsd.a).
In the Version 4 of the operating system, the parent process does not have to wait until the child either exits or executes, as it does in BSD systems. The child process is given a new address space, as in the fork subroutine. The child process does not share any parent address space.
Attention: When using the fork or vfork subroutines with an Enhanced X-Windows, X Toolkit, or Motif application, a separate display connection (socket) should be opened for the forked process. Use the XOpenDisplay or the XtOpenDisplay subroutines to open the separate connection. The child process should never use the same display connection as the parent. Display connections are embodied with sockets, and sockets are inherited by the child process. Any attempt to have multiple processes writing to the same display connection results in the random interleaving of X protocol packets at the word level. The resulting data written to the socket will not be valid or undefined X protocol packets, and the X Server will not be able to interpret it.
Attention: Although the fork and vfork subroutine may be used with Graphics Library applications, the child process must not make any additional Graphics Library subroutine calls. The child application inherits some, but not all of the graphics hardware resources of the parent. Drawing by the child process may hang the graphics adapter, the Enhanced X Server, or may cause unpredictable results and place the system into an unpredictable state.
Note: Some Graphics Library subroutines, such as the winopen subroutine, implicitly create an X display connection. This connection may be obtained with the getXdpy subroutine.
For additional information, see the /usr/lpp/GL/README file.
The alarm subroutine, bindprocessor subroutine, exec subroutine, exit, atexit, or _exit subroutine, getrusage or times subroutine, getXdpy subroutine, incinterval subroutine, nice subroutine, plock subroutine, pthread_atfork subroutine, ptrace subroutine, raise subroutine, semop subroutine, setitimer subroutine, shmat subroutine, setpriority or getpriority subroutine, sigaction, sigvec, or signal subroutine, ulimit subroutine, umask subroutine, wait, waitpid, or wait3 subroutine, winopen subroutine, XOpenDisplay subroutine, XtOpenDisplay subroutine.
Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.
Process Duplication and Termination in AIX Version 4.3 General Programming Concepts: Writing and Debugging ProgramsLK provides more information about forking a multi-threaded process.