⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fork.html

📁 posix标准英文,html格式
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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-2004 IEEE and The Open Group, All Rights Reserved --><title>fork</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="fork"></a> <a name="tag_03_177"></a><!-- fork --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright &copy; 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_177_01"></a>NAME</h4><blockquote>fork - create a new process</blockquote><h4><a name="tag_03_177_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br><br> pid_t fork(void);<br></tt></code></p></blockquote><h4><a name="tag_03_177_03"></a>DESCRIPTION</h4><blockquote><p>The <i>fork</i>() function shall create a new process. The new process (child process) shall be an exact copy of the callingprocess (parent process) except as detailed below:</p><ul><li><p>The child process shall have a unique process ID.</p></li><li><p>The child process ID also shall not match any active process group ID.</p></li><li><p>The child process shall have a different parent process ID, which shall be the process ID of the calling process.</p></li><li><p>The child process shall have its own copy of the parent's file descriptors. Each of the child's file descriptors shall refer tothe same open file description with the corresponding file descriptor of the parent.</p></li><li><p>The child process shall have its own copy of the parent's open directory streams. Each open directory stream in the childprocess may share directory stream positioning with the corresponding directory stream of the parent.</p></li><li><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The child process shall have its own copy of the parent's message catalog descriptors. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p>The child process' values of <i>tms_utime</i>, <i>tms_stime</i>, <i>tms_cutime</i>, and <i>tms_cstime</i> shall be set to 0.</p></li><li><p>The time left until an alarm clock signal shall be reset to zero, and the alarm, if any, shall be canceled; see <a href="alarm.html"><i>alarm</i>()</a>.</p></li><li><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">All <i>semadj</i> values shall be cleared. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p>File locks set by the parent process shall not be inherited by the child process.</p></li><li><p>The set of signals pending for the child process shall be initialized to the empty set.</p></li><li><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Interval timers shall be reset in the child process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('SEM')">SEM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any semaphores that are open in the parent process shall also be open in the child process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('ML')">ML</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Thechild process shall not inherit any address space memory locks established by the parent process via calls to <a href="../functions/mlockall.html"><i>mlockall</i>()</a> or <a href="../functions/mlock.html"><i>mlock</i>()</a>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('MF')">MF|SHM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Memory mappings created in the parent shall be retained in the child process. MAP_PRIVATE mappings inherited from the parent shallalso be MAP_PRIVATE mappings in the child, and any modifications to the data in these mappings made by the parent prior to calling<i>fork</i>() shall be visible to the child. Any modifications to the data in MAP_PRIVATE mappings made by the parent after<i>fork</i>() returns shall be visible only to the parent. Modifications to the data in MAP_PRIVATE mappings made by the childshall be visible only to the child. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('PS')">PS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Forthe SCHED_FIFO and SCHED_RR scheduling policies, the child process shall inherit the policy and priority settings of the parentprocess during a <i>fork</i>() function. For other scheduling policies, the policy and priority settings on <i>fork</i>() areimplementation-defined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('TMR')">TMR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Per-process timers created by the parent shall not be inherited by the child process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('MSG')">MSG</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The child process shall have its own copy of the message queue descriptors of the parent. Each of the message descriptors of thechild shall refer to the same open message queue description as the corresponding message descriptor of the parent. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('AIO')">AIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">No asynchronous input or asynchronous output operations shall be inherited by the child process. <img src="../images/opt-end.gif"alt="[Option End]" border="0"></p></li><li><p>A process shall be created with a single thread. If a multi-threaded process calls <i>fork</i>(), the new process shall containa replica of the calling thread and its entire address space, possibly including the states of mutexes and other resources.Consequently, to avoid errors, the child process may only execute async-signal-safe operations until such time as one of the <i><ahref="../functions/exec.html">exec</a></i> functions is called. <sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <imgsrc="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;Fork handlers may be established by means of the <a href="../functions/pthread_atfork.html"><i>pthread_atfork</i>()</a> function in order to maintain application invariants across<i>fork</i>() calls. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>When the application calls <i>fork</i>() from a signal handler and any of the fork handlers registered by <a href="../functions/pthread_atfork.html"><i>pthread_atfork</i>()</a> calls a function that is not asynch-signal-safe, the behavior isundefined.</p></li><li><p><sup>[<a href="javascript:open_code('TRC TRI')">TRC TRI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> If the Trace option and the Trace Inherit option are both supported:</p><p>If the calling process was being traced in a trace stream that had its inheritance policy set to POSIX_TRACE_INHERITED, thechild process shall be traced into that trace stream, and the child process shall inherit the parent's mapping of trace event namesto trace event type identifiers. If the trace stream in which the calling process was being traced had its inheritance policy setto POSIX_TRACE_CLOSE_FOR_CHILD, the child process shall not be traced into that trace stream. The inheritance policy is set by acall to the <a href="../functions/posix_trace_attr_setinherited.html"><i>posix_trace_attr_setinherited</i>()</a> function. <imgsrc="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('TRC')">TRC</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If the Trace option is supported, but the Trace Inherit option is not supported:</p><p>The child process shall not be traced into any of the trace streams of its parent process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('TRC')">TRC</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If the Trace option is supported, the child process of a trace controller process shall not control the trace streams controlled byits parent process. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('CPT')">CPT</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The initial value of the CPU-time clock of the child process shall be set to zero. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p><sup>[<a href="javascript:open_code('TCT')">TCT</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The initial value of the CPU-time clock of the single thread of the child process shall be set to zero. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li></ul><p>All other process characteristics defined by IEEE&nbsp;Std&nbsp;1003.1-2001 shall be the same in the parent and child processes.The inheritance of process characteristics not defined by IEEE&nbsp;Std&nbsp;1003.1-2001 is unspecified byIEEE&nbsp;Std&nbsp;1003.1-2001.</p><p>After <i>fork</i>(), both the parent and the child processes shall be capable of executing independently before either oneterminates.</p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -