📄 vfork.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>vfork</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="vfork"></a> <a name="tag_03_809"></a><!-- vfork --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_809_01"></a>NAME</h4><blockquote>vfork - create a new process; share virtual memory</blockquote><h4><a name="tag_03_809_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('OB XSI')">OB XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/unistd.h.html">unistd.h</a>><br><br> pid_t vfork(void); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_809_03"></a>DESCRIPTION</h4><blockquote><p>The <i>vfork</i>() function shall be equivalent to <a href="../functions/fork.html"><i>fork</i>()</a>, except that the behavioris undefined if the process created by <i>vfork</i>() either modifies any data other than a variable of type <b>pid_t</b> used tostore the return value from <i>vfork</i>(), or returns from the function in which <i>vfork</i>() was called, or calls any otherfunction before successfully calling <a href="../functions/_exit.html"><i>_exit</i>()</a> or one of the <i><a href="../functions/exec.html">exec</a></i> family of functions.</p></blockquote><h4><a name="tag_03_809_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>vfork</i>() shall return 0 to the child process and return the process ID of the child process tothe parent process. Otherwise, -1 shall be returned to the parent, no child process shall be created, and <i>errno</i> shall be setto indicate the error.</p></blockquote><h4><a name="tag_03_809_05"></a>ERRORS</h4><blockquote><p>The <i>vfork</i>() function shall fail if:</p><dl compact><dt>[EAGAIN]</dt><dd>The system-wide limit on the total number of processes under execution would be exceeded, or the system-imposed limit on thetotal number of processes under execution by a single user would be exceeded.</dd><dt>[ENOMEM]</dt><dd>There is insufficient swap space for the new process.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_809_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_809_07"></a>APPLICATION USAGE</h4><blockquote><p>Conforming applications are recommended not to depend on <i>vfork</i>(), but to use <a href="../functions/fork.html"><i>fork</i>()</a> instead. The <i>vfork</i>() function may be withdrawn in a future version.</p><p>On some implementations, <i>vfork</i>() is equivalent to <a href="../functions/fork.html"><i>fork</i>()</a>.</p><p>The <i>vfork</i>() function differs from <a href="../functions/fork.html"><i>fork</i>()</a> only in that the child process canshare code and data with the calling process (parent process). This speeds cloning activity significantly at a risk to theintegrity of the parent process if <i>vfork</i>() is misused.</p><p>The use of <i>vfork</i>() for any purpose except as a prelude to an immediate call to a function from the <i><a href="../functions/exec.html">exec</a></i> family, or to <a href="../functions/_exit.html"><i>_exit</i>()</a>, is not advised.</p><p>The <i>vfork</i>() function can be used to create new processes without fully copying the address space of the old process. If aforked process is simply going to call <i><a href="../functions/exec.html">exec</a></i>, the data space copied from the parent tothe child by <a href="../functions/fork.html"><i>fork</i>()</a> is not used. This is particularly inefficient in a pagedenvironment, making <i>vfork</i>() particularly useful. Depending upon the size of the parent's data space, <i>vfork</i>() can givea significant performance improvement over <a href="../functions/fork.html"><i>fork</i>()</a>.</p><p>The <i>vfork</i>() function can normally be used just like <a href="../functions/fork.html"><i>fork</i>()</a>. It does not work,however, to return while running in the child's context from the caller of <i>vfork</i>() since the eventual return from<i>vfork</i>() would then return to a no longer existent stack frame. Care should be taken, also, to call <a href="../functions/_exit.html"><i>_exit</i>()</a> rather than <a href="../functions/exit.html"><i>exit</i>()</a> if <i><a href="../functions/exec.html">exec</a></i> cannot be used, since <a href="../functions/exit.html"><i>exit</i>()</a> flushes and closesstandard I/O channels, thereby damaging the parent process' standard I/O data structures. (Even with <a href="../functions/fork.html"><i>fork</i>()</a>, it is wrong to call <a href="../functions/exit.html"><i>exit</i>()</a>, since buffereddata would then be flushed twice.)</p><p>If signal handlers are invoked in the child process after <i>vfork</i>(), they must follow the same rules as other code in thechild process.</p></blockquote><h4><a name="tag_03_809_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_809_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>This function may be withdrawn in a future version.</p></blockquote><h4><a name="tag_03_809_10"></a>SEE ALSO</h4><blockquote><p><a href="exec.html"><i><a href="../functions/exec.html">exec</a></i>()</a> , <a href="exit.html"><i>exit</i>()</a> , <a href="fork.html"><i>fork</i>()</a> , <a href="wait.html"><i>wait</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/unistd.h.html"><i><unistd.h></i></a></p></blockquote><h4><a name="tag_03_809_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_809_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p></blockquote><h4><a name="tag_03_809_13"></a>Issue 6</h4><blockquote><p>This function is marked obsolescent.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -