DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

vfork(S-osr5)


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-osr5) would have been to create a new system context for an execve(S-osr5). 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-osr5) 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-osr5) operations are allowed and input attempts result in an EOF indication.

Be careful, also, to call _exit(S-osr5) 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-osr5), exit(S-osr5), fork(S-osr5), ioctl(S-osr5), wait(S-osr5)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005