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

📄 exec.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>exec</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_004_056">&nbsp;</a>NAME</h4><blockquote>environ, execl, execv, execle, execve, execlp, execvp - execute a file</blockquote><h4><a name = "tag_000_004_057">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>#include &lt;<a href="unistd.h.html">unistd.h</a>&gt;extern char **environ;int execl(const char *<i>path</i>, const char *<i>arg0</i>, ... /*, (char *)0 */);int execv(const char *<i>path</i>, char *const <i>argv</i>[]);int execle(const char *<i>path</i>,    const char *<i>arg0</i>, ... /*, (char *)0, char *const <i>envp</i>[]*/);int execve(const char *<i>path</i>, char *const <i>argv</i>[], char *const <i>envp</i>[]);int execlp(const char *<i>file</i>, const char *<i>arg0</i>, ... /*, (char *)0 */);int execvp(const char *<i>file</i>, char *const <i>argv</i>[]);</code></pre></blockquote><h4><a name = "tag_000_004_058">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>exec</i>functions replace the current process image with anew process image.The new image is constructed from a regular, executable filecalled the<i>new process image file</i>.There is no return from a successful<i>exec</i>,because the calling process image is overlaid by the new processimage.<p>When a C-language program is executed as a result of this call, it isentered as a C-language function call as follows:<pre><code>int main (<i>int argc, char *argv</i>[]);</code></pre>where<i>argc</i>is the argument count and<i>argv</i>is an array of character pointers to the arguments themselves.In addition, the following variable:<pre><code>extern char **environ;</code></pre>is initialised as a pointer to an array of character pointers tothe 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>Conforming multi-threaded applications will not use the<i>environ</i>variable to access or modify any environment variablewhile any other thread is concurrently modifying any environmentvariable.A call to any function dependent on any environment variableis considered a use of the<i>environ</i>variable to access that environment variable.<p>The arguments specified by a program with one of the<i>exec</i>functions are passed on to the new process image in thecorresponding<i>main()</i>arguments.<p>The argument<i>path</i>points to a pathname that identifies the new process image file.<p>The argument<i>file</i>is used to construct a pathname that identifies the new processimage file.If the<i>file</i>argument contains a slash character, the<i>file</i>argument is used as the pathname for this file.Otherwise, thepath prefix forthis file is obtained by a search of the directories passed asthe environment variable(see <b>XBD</b> specification, <a href="../xbd/envvar.html"><b>Environment Variables</b>&nbsp;</a> ).If this environment variable is not present, the results of thesearch are implementation-dependent.<p>If the process image file is not a valid executable object,<i><a href="exec.html">execlp()</a></i>and<i><a href="exec.html">execvp()</a></i>use the contents of that file as standard input to acommand interpreter conforming to<i><a href="system.html">system()</a></i>.In this case, the command interpreter becomes the new process image.<p>The arguments represented by<i>arg0, ...</i>are pointers to null-terminated character strings.These strings constitute the argument list available to the newprocess image.The list is terminated by a null pointer.The argument<i>arg0</i>should point to a filename that is associated with the processbeing started by one of the<i>exec</i>functions.<p>The argument<i>argv</i>is an array of character pointers to null-terminated strings.The last member of this array must be a null pointer.These strings constitute the argument list available to the newprocess image.The value in<i>argv[0]</i>should point to a filename that is associated with the processbeing started by one of the<i>exec</i>functions.<p>The argument<i>envp</i>is an array of character pointers to null-terminated strings.These strings constitute the environment for the new processimage.The<i>envp</i>array is terminated by a null pointer.<p>For those forms not containing an<i>envp</i>pointer (.Fn execl ,<i><a href="exec.html">execv()</a></i>,<i><a href="exec.html">execlp()</a></i>and<i><a href="exec.html">execvp()</a></i>),the environment for the new process image is taken from theexternal variable<i>environ</i>in the calling process.<p>The number of bytes available for the new process' combinedargument and environment lists is {ARG_MAX}.It is implementation-dependentwhether null terminators, pointers, and/or any alignmentbytes are included in this total.<p>File descriptors open in the calling process image remain open inthe new process image, except for those whose close-on-exec flagFD_CLOEXEC is set.For those file descriptors that remain open, all attributes ofthe open file description, including file locks remainunchanged.<p>Directory streams open in the calling process image are closedin the new process image.<p>The state of conversion descriptorsand message catalogue descriptorsin the new process image is undefined.For the new process, the equivalent of:<pre><code>setlocale(LC_ALL, "C")</code></pre><p>is executed at startup.<p>Signals set to the default action (SIG_DFL) in the calling process imageare set to the default action in the new process image. Signals set to beignored (SIG_IGN) by the calling process image are set to beignored by the newprocess image. Signals set to be caught by the calling process image areset to the default action in the new process image (see<i><a href="signal.h.html">&lt;signal.h&gt;</a></i>).&nbsp;After a successful call to any of the<i>exec</i>functions, alternate signal stacks are not preserved and the SA_ONSTACK flagis cleared for all signals.<p>After a successful call to any of the<i>exec</i>functions, any functions previously registered by<i><a href="atexit.html">atexit()</a></i>are no longer registered.<p>If the ST_NOSUID bit is set for the file system containing the new processimage file, then the effective user ID, effective group ID, saved set-user-IDand saved set-group-ID are unchanged in the new process image.  Otherwise,if the set-user-ID mode bit of the new process image file is set,the effective user ID of the new process image is set to the user IDof the new process image file. Similarly, if the set-group-ID mode bit ofthe new process image file is set, the effective group ID of the newprocess image is set to the group ID of the new process image file. Thereal user ID, real group ID, and supplementary group IDs of the new processimage remain the same as those of the calling process image.The effective user ID and effective groupID of the new process image are saved (as the saved set-user-ID and thesaved set-group-ID for use by<i><a href="setuid.html">setuid()</a></i>.<p>Any shared memory segments attached to the calling process imagewill not be attached to the new process image.<p>Any mappings established through<i><a href="mmap.html">mmap()</a></i>are not preserved across an<i>exec</i>.<p>If _XOPEN_REALTIME is definedand has a value other than -1,any named semaphoresopen in the calling process are closedas if by appropriate calls to<i><a href="sem_close.html">sem_close()</a></i>.<p>If the Process Memory Locking option is supported,memory locks established by the calling process via calls to<i><a href="mlockall.html">mlockall()</a></i>or<i><a href="mlock.html">mlock()</a></i>are removed.If locked pages in the address space of the calling processare also mapped into the address spacesof other processes and are locked by those processes,the locks established by the other processes will be unaffectedby the call by this process to the<i>exec</i>function.If the<i>exec</i>function fails, the effect on memory locks is unspecified.<p>Memory mappings created in the process are unmapped before theaddress space is rebuilt for the new process image.<p>If the Process Scheduling option is supported,for the SCHED_FIFO and SCHED_RR scheduling policies,the policy and priority settings are not 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-dependent.<p>If the Timers option is supported,per-process timers created by the calling processare deleted before replacing the current process image

⌨️ 快捷键说明

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