DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

vfork(S)


vfork -- spawn new process in a virtual memory efficient way

Syntax

cc . . . -lc
#include <unistd.h>

pid_t vfork (void);

Description

vfork can be used to create new processes without fully copying the address space of the old process. It is useful when the purpose of fork(S) would have been to create a new system context for an execve(S). vfork differs from fork in that the parent process sleeps until the child process calls execve or exits either by a call to exit(S) or abnormally. The parent process sleeps while the child is using its resources.

vfork returns 0 in the child's context and (later) the process ID (PID) of the child in the parent's context.

vfork can normally be used just like fork. However, it is recommended that wherever possible, fork be used instead of vfork, in order to enhance portability.

Return values

On success, vfork returns 0 to the child process and returns the process ID of the child process to the parent process. On failure, vfork returns -1, sets errno to identify the error, and no child process is created.

Diagnostics

In the following conditions, vfork fails and sets errno to:

[EAGAIN]
The system-imposed limit on the total number of processes under execution would be exceeded. This limit is determined when the system is generated.

[EAGAIN]
The system-imposed limit on the total number of processes under execution by a single user would be exceeded. This limit is determined when the system is generated.

[ENOMEM]
There is insufficient swap space for the new process.

Limitations

To avoid a possible deadlock situation, processes that are children in the middle of a vfork are never sent SIGTTOU or SIGTTIN signals; rather, output or ioctl(S) operations are allowed and input attempts result in an EOF indication.

Be careful, also, to call _exit(S) rather than exit if you cannot execve, since exit will flush and close standard I/O channels, and thereby mess up the parent processes standard I/O data structures. Even with fork it is wrong to call exit since buffered data would then be flushed twice.

Files


/lib/libc.a
linking library

See also

exec(S), exit(S), fork(S), ioctl(S), wait(S)
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003