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

📄 execv.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<!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>exec</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="exec"></a> <a name="tag_03_130"></a><!-- exec --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_130_01"></a>NAME</h4><blockquote>environ, execl, execv, execle, execve, execlp, execvp - execute a file</blockquote><h4><a name="tag_03_130_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include &lt;<a href="../basedefs/unistd.h.html">unistd.h</a>&gt;<br><br> extern char **environ;<br> int execl(const char *</tt><i>path</i><tt>, const char *</tt><i>arg0</i><tt>, ... /*, (char *)0 */);<br> int execv(const char *</tt><i>path</i><tt>, char *const</tt> <i>argv</i><tt>[]);<br> int execle(const char *</tt><i>path</i><tt>, const char *</tt><i>arg0</i><tt>, ... /*,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (char *)0, char *const</tt> <i>envp</i><tt>[]*/);<br> int execve(const char *</tt><i>path</i><tt>, char *const</tt> <i>argv</i><tt>[], char *const</tt> <i>envp</i><tt>[]);<br> int execlp(const char *</tt><i>file</i><tt>, const char *</tt><i>arg0</i><tt>, ... /*, (char *)0 */);<br> int execvp(const char *</tt><i>file</i><tt>, char *const</tt> <i>argv</i><tt>[]);<br></tt></code></p></blockquote><h4><a name="tag_03_130_03"></a>DESCRIPTION</h4><blockquote><p>The <i>exec</i> family of functions shall replace the current process image with a new process image. The new image shall beconstructed from a regular, executable file called the <i>new process image file</i>. There shall be no return from a successful<i>exec</i>, because the calling process image is overlaid by the new process image.</p><p>When a C-language program is executed as a result of this call, it shall be entered as a C-language function call asfollows:</p><pre><tt>int main (</tt><i>int argc, char *argv</i><tt>[]);</tt></pre><p>where <i>argc</i> is the argument count and <i>argv</i> is an array of character pointers to the arguments themselves. Inaddition, the following variable:</p><pre><tt>extern char **environ;</tt></pre><p>is initialized as a pointer to an array of character pointers to the environment strings. The <i>argv</i> and <i>environ</i>arrays are each terminated by a null pointer. The null pointer terminating the <i>argv</i> array is not counted in <i>argc</i>.</p><p><sup>[<a href="javascript:open_code('THR')">THR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Conforming multi-threaded applications shall not use the <i>environ</i> variable to access or modify any environment variable whileany other thread is concurrently modifying any environment variable. A call to any function dependent on any environment variableshall be considered a use of the <i>environ</i> variable to access that environment variable. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The arguments specified by a program with one of the <i>exec</i> functions shall be passed on to the new process image in thecorresponding <i>main</i>() arguments.</p><p>The argument <i>path</i> points to a pathname that identifies the new process image file.</p><p>The argument <i>file</i> is used to construct a pathname that identifies the new process image file. If the <i>file</i> argumentcontains a slash character, the <i>file</i> argument shall be used as the pathname for this file. Otherwise, the path prefix forthis file is obtained by a search of the directories passed as the environment variable <i>PATH</i> (see the Base Definitionsvolume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>). If thisenvironment variable is not present, the results of the search are implementation-defined.</p><p>There are two distinct ways in which the contents of the process image file may cause the execution to fail, distinguished bythe setting of <i>errno</i> to either [ENOEXEC] or [EINVAL] (see the ERRORS section). In the cases where the other members of the<i>exec</i> family of functions would fail and set <i>errno</i> to [ENOEXEC], the <i>execlp</i>() and <i>execvp</i>() functionsshall execute a command interpreter and the environment of the executed command shall be as if the process invoked the <a href="../utilities/sh.html"><i>sh</i></a> utility using <i>execl</i>() as follows:</p><pre><tt>execl(&lt;shell path&gt;, arg0, file, arg1, ..., (char *)0);</tt></pre><p>where &lt;<i>shell&nbsp;path</i>&gt; is an unspecified pathname for the <a href="../utilities/sh.html"><i>sh</i></a> utility,<i>file</i> is the process image file, and for <i>execvp</i>(), where <i>arg</i>0, <i>arg</i>1, and so on correspond to the valuespassed to <i>execvp</i>() in <i>argv</i>[0], <i>argv</i>[1], and so on.</p><p>The arguments represented by <i>arg0</i>,... are pointers to null-terminated character strings. These strings shall constitutethe argument list available to the new process image. The list is terminated by a null pointer. The argument <i>arg0</i> shouldpoint to a filename that is associated with the process being started by one of the <i>exec</i> functions.</p><p>The argument <i>argv</i> is an array of character pointers to null-terminated strings. The application shall ensure that thelast member of this array is a null pointer. These strings shall constitute the argument list available to the new process image.The value in <i>argv</i>[0] should point to a filename that is associated with the process being started by one of the <i>exec</i>functions.</p><p>The argument <i>envp</i> is an array of character pointers to null-terminated strings. These strings shall constitute theenvironment for the new process image. The <i>envp</i> array is terminated by a null pointer.</p><p>For those forms not containing an <i>envp</i> pointer ( <i>execl</i>(), <i>execv</i>(), <i>execlp</i>(), and <i>execvp</i>()),the environment for the new process image shall be taken from the external variable <i>environ</i> in the calling process.</p><p>The number of bytes available for the new process' combined argument and environment lists is {ARG_MAX}. It isimplementation-defined whether null terminators, pointers, and/or any alignment bytes are included in this total.</p><p>File descriptors open in the calling process image shall remain open in the new process image, except for those whose close-on-<i>exec</i> flag FD_CLOEXEC is set. For those file descriptors that remain open, all attributes of the open file description remainunchanged. For any file descriptor that is closed for this reason, file locks are removed as a result of the close as described in<a href="close.html"><i>close</i>()</a> . Locks that are not removed by closing of file descriptors remain unchanged.</p><p>If file descriptors 0, 1, and 2 would otherwise be closed after a successful call to one of the <i>exec</i> family of functions,and the new process image file has the set-user-ID or set-group-ID file mode bits set, <sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> &nbsp;and theST_NOSUID bit is not set for the file system containing the new process image file, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> implementations may open an unspecified file for each of these file descriptors in the new processimage.</p><p>Directory streams open in the calling process image shall be closed in the new process image.</p><p>The state of the floating-point environment in the new process image shall be set to the default.</p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The state of conversion descriptors and message catalog descriptors in the new process image is undefined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> &nbsp;For the new process image, the equivalent of:</p><pre><tt>setlocale(LC_ALL, "C")</tt></pre><p>shall be executed at start-up.</p><p>Signals set to the default action (SIG_DFL) in the calling process image shall be set to the default action in the new processimage. Except for SIGCHLD, signals set to be ignored (SIG_IGN) by the calling process image shall be set to be ignored by the newprocess image. Signals set to be caught by the calling process image shall be set to the default action in the new process image(see <a href="../basedefs/signal.h.html"><i>&lt;signal.h&gt;</i></a>). If the SIGCHLD signal is set to be ignored by the callingprocess image, it is unspecified whether the SIGCHLD signal is set to be ignored or to the default action in the new process image.<sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">&nbsp;After a successful call to any of the <i>exec</i> functions, alternate signal stacks are not preserved and the SA_ONSTACKflag shall be cleared for all signals. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>After a successful call to any of the <i>exec</i> functions, any functions previously registered by <a href="../functions/atexit.html"><i>atexit</i>()</a> are no longer registered.</p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If the ST_NOSUID bit is set for the file system containing the new process image file, then the effective user ID, effective groupID, saved set-user-ID, and saved set-group-ID are unchanged in the new process image. Otherwise, <img src="../images/opt-end.gif"alt="[Option End]" border="0"> if the set-user-ID mode bit of the new process image file is set, the effective user ID of the newprocess image shall be set to the user ID of the new process image file. Similarly, if the set-group-ID mode bit of the new processimage file is set, the effective group ID of the new process image shall be set to the group ID of the new process image file. Thereal user ID, real group ID, and supplementary group IDs of the new process image shall remain the same as those of the callingprocess image. The effective user ID and effective group ID of the new process image shall be saved (as the saved set-user-ID andthe saved set-group-ID) for use by <a href="../functions/setuid.html"><i>setuid</i>()</a>.</p><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any shared memory segments attached to the calling process image shall not be attached to the new process image. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('SEM')">SEM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any named semaphores open in the calling process shall be closed as if by appropriate calls to <a href="../functions/sem_close.html"><i>sem_close</i>()</a>. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('TYM')">TYM</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any blocks of typed memory that were mapped in the calling process are unmapped, as if <a href="../functions/munmap.html"><i>munmap</i>()</a> was implicitly called to unmap them. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('ML')">ML</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Memory locks established by the calling process via calls to <a href="../functions/mlockall.html"><i>mlockall</i>()</a> or <a href="../functions/mlock.html"><i>mlock</i>()</a> shall be removed. If locked pages in the address space of the calling process are alsomapped into the address spaces of other processes and are locked by those processes, the locks established by the other processesshall be unaffected by the call by this process to the <i>exec</i> function. If the <i>exec</i> function fails, the effect onmemory locks is unspecified. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><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 process are unmapped before the address space is rebuilt for the new process image. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><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 policy and priority settings shall not be changed by a call to an <i>exec</i>function. For other scheduling policies, the policy and priority settings on <i>exec</i> are implementation-defined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><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 calling process shall be deleted before replacing the current process image with the new processimage. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('MSG')">MSG</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">All open message queue descriptors in the calling process shall be closed, as described in <a href="mq_close.html"><i>mq_close</i>()</a> . <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('AIO')">AIO</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Any outstanding asynchronous I/O operations may be canceled. Those asynchronous I/O operations that are not canceled shall completeas if the <i>exec</i> function had not yet occurred, but any associated signal notifications shall be suppressed. It is unspecifiedwhether the <i>exec</i> function itself blocks awaiting such I/O completion. In no event, however, shall the new process imagecreated by the <i>exec</i> function be affected by the presence of outstanding asynchronous I/O operations at the time the<i>exec</i> function is called. Whether any I/O is canceled, and which I/O may be canceled upon <i>exec</i>, isimplementation-defined. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('CPT')">CPT</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">The new process image shall inherit the CPU-time clock of the calling process image. This inheritance means that the processCPU-time clock of the process being <i>exec</i>-ed shall not be reinitialized or altered as a result of the <i>exec</i> functionother than to reflect the time spent by the process executing the <i>exec</i> function itself. <img src="../images/opt-end.gif"alt="[Option End]" border="0"></p><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 initial thread of the new process image shall be set to zero. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p><sup>[<a href="javascript:open_code('TRC')">TRC</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">If the calling process is being traced, the new process image shall continue to be traced into the same trace stream as theoriginal process image, but the new process image shall not inherit the mapping of trace event names to trace event typeidentifiers that was defined by calls to the <a href="../functions/posix_trace_eventid_open.html"><i>posix_trace_eventid_open</i>()</a> or the <a href="../functions/posix_trace_trid_eventid_open.html"><i>posix_trace_trid_eventid_open</i>()</a> functions in the calling processimage.</p><p>If the calling process is a trace controller process, any trace streams that were created by the calling process shall be shutdown as described in the <a href="../functions/posix_trace_shutdown.html"><i>posix_trace_shutdown</i>()</a> function. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><p>The new process shall inherit at least the following attributes from the calling process image:</p><ul><li><p><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Nice value (see <a href="nice.html"><i>nice</i>()</a> ) <img src="../images/opt-end.gif" alt="[Option End]" border="0"></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"><i>semadj</i> values (see <a href="semop.html"><i>semop</i>()</a> ) <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p>Process ID</p></li><li><p>Parent process ID</p></li><li><p>Process group ID</p></li><li><p>Session membership</p></li><li><p>Real user ID</p></li><li><p>Real group ID</p></li><li><p>Supplementary group IDs</p></li><li><p>Time left until an alarm clock signal (see <a href="alarm.html"><i>alarm</i>()</a> )</p></li><li><p>Current working directory</p></li><li><p>Root directory</p></li><li><p>File mode creation mask (see <a href="umask.html"><i>umask</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">File size limit (see <a href="ulimit.html"><i>ulimit</i>()</a> ) <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li><li><p>Process signal mask (see <a href="sigprocmask.html"><i>sigprocmask</i>()</a> )</p></li><li><p>Pending signal (see <a href="sigpending.html"><i>sigpending</i>()</a> )</p></li><li><p><i>tms_utime</i>, <i>tms_stime</i>, <i>tms_cutime</i>, and <i>tms_cstime</i> (see <a href="times.html"><i>times</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">Resource limits <img src="../images/opt-end.gif" alt="[Option End]" border="0"></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">Controlling terminal <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p></li>

⌨️ 快捷键说明

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