Re: Porting vfork()

Brandon S. Allbery KF8NH (allbery@kf8nh.apk.net)
Sun, 10 Jan 1999 15:42:32 -0500


In message <Pine.LNX.4.05.9901100143580.27606-100000@pele.fairplay.no>,
Torbjor
n Lindgren writes:
+-----
| In the description they note that some systems vfork() is the same as
| fork(), so presumably that is allowed (you just have to alias it so vfork
| exist?). And NOWHERE is there anything about suspending the original
| process, so I think a traditional vfork() implementation (like Solaris) is
| non-SUSv2-conforming anyway!?!
|
| The requirements are basically (paraphrased):
| * Don't modify any data other than a variable of type pid_t used to store
| the return value from vfork()
| * Don't return from the function in which vfork() was called.
| * Don't call any functions before successfully calling _exit(),or one of
| the exec family of functions.
+--->8

The restrictions are consistent with safety requirements when using a "true"
vfork(), so Solaris's implementation is valid. SUS is simply saying that
vfork() *may* be fork() but *might* be something weirder (i.e. the silly
workaround for early VAX broken copy-on-write that some people on this list
think is a good thing).

| in their manual pages. The closest to a BSD4.x box I could find (Ultrix
| 4.4) didn't have it thought, so the original BSD implementations might
| not have had it...
+--->8

vfork(2)

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

Syntax
pid = vfork()
int pid;

Description
The vfork can be used to create new processes without fully copying the
address space of the old process, which is inefficient in a paged
environment. It is useful when the purpose of fork would have been to
create a new system context for an execve. The vfork system call
differs from fork in that the child borrows the parent's memory and
thread of control until a call to execve or an exit (either by a call to
exit(2) or abnormally.) The parent process is suspended while the child
is using its resources.

The vfork system call returns a value of zero (0) in the child's context
and, later, the pid of the child in the parent's context.

The vfork system call can normally be used just like fork. It does not
work, however, to return while running in the childs context from the
procedure which called vfork, because the eventual return from vfork
would then return to a nonexistent stack frame. Be careful, also, to
call _exit rather than exit if you cannot call execve, because exit will
flush and close standard I/O channels and thereby cause problems in the
parent process's standard I/O data structures. Even with fork it is
wrong to call exit, because buffered data would then be flushed twice.

Restrictions
To avoid a possible deadlock situation, processes which are children in
the middle of a vfork are never sent SIGTTOU or SIGTTIN signals.
Rather, output or ioctls are allowed, and input attempts result in an
end-of-file indication.

Diagnostics
Same as for fork.

See Also
execve(2), fork(2), sigvec(2), wait(2)

1
(Taken from:
skukkuk:501 B$ uname -a
ULTRIX skukkuk 4.4 0 RISC unknown
)

-- 
brandon s. allbery	[os/2][linux][solaris][japh]	 allbery@kf8nh.apk.net
system administrator	     [WAY too many hats]	   allbery@ece.cmu.edu
carnegie mellon / electrical and computer engineering			 KF8NH
     We are Linux. Resistance is an indication that you missed the point.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/