📄 _exit.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>exit</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_004_065"> </a>NAME</h4><blockquote>exit, _exit - terminate a process</blockquote><h4><a name = "tag_000_004_066"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="stdlib.h.html">stdlib.h</a>>void exit(int <i>status</i>);#include <<a href="unistd.h.html">unistd.h</a>>void _exit(int <i>status</i>);</code></pre></blockquote><h4><a name = "tag_000_004_067"> </a>DESCRIPTION</h4><blockquote>The<i>exit()</i>function first calls all functions registered by<i><a href="atexit.html">atexit()</a></i>,in the reverse order of their registration.Each function is called as many times as it was registered.<p>If a function registered by a call to<i><a href="atexit.html">atexit()</a></i>fails to return, the remaining registered functionsare not called and the rest of the<i>exit()</i>processing is not completed. If<i>exit()</i>is called more than once, the effects are undefined.<p>The<i>exit()</i>function then flushes all output streams, closes all open streams,and removes all files created by<i><a href="tmpfile.html">tmpfile()</a></i>.Finally, control is returned to the host environment as describedbelow.The values of<i>status</i>can be EXIT_SUCCESS or EXIT_FAILURE,as described in<i><a href="stdlib.h.html"><stdlib.h></a></i>,or any implementation-dependent value, although note that only the range0 through 255 will be available to a waiting parent process.<p>The<i>_exit()</i>and<i>exit()</i>functions terminate the calling process with the following consequences:<ul><p><li>All of the file descriptors, directory streams, conversion descriptors and message catalogue descriptorsopen in the calling process are closed.<p><li>If the parent process of the calling process is executing a<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>or<i><a href="waitpid.html">waitpid()</a></i>,and has neither set its SA_NOCLDWAIT flag nor set SIGCHLD to SIG_IGN,it is notified of the calling process'termination and the low-order eight bits (that is, bits 0377) of<i>status</i>are made available to it. If the parent is not waiting, the child's statuswill be made available to it when the parent subsequently executes<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>or<i><a href="waitpid.html">waitpid()</a></i>.<p><li>If the parent process of the calling process is notexecuting a<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>or<i><a href="waitpid.html">waitpid()</a></i>,and has not set its SA_NOCLDWAIT flag,or set SIGCHLD to SIG_IGN,the calling process is transformed into a <i>zombie process</i>.A <i>zombie process</i> is an inactive processand it will be deleted at some later timewhen its parent process executes<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>or<i><a href="waitpid.html">waitpid()</a></i>.<p><li>Termination of a process does not directly terminate its children. Thesending of a SIGHUPsignal as described below indirectly terminates children in somecircumstances.<p><li>If the implementation supports the SIGCHLDsignal, a SIGCHLDwill be sent to the parent process.<p><li>If the parent process has set its SA_NOCLDWAIT flag,or set SIGCHLD to SIG_IGN, the status will bediscarded, and the lifetime of the calling process will end immediately.If SA_NOCLDWAIT is set, it is implementation-dependent whether aSIGCHLD signal will be sent to the parent process.<p><li>The parent process ID of all of the calling process'existing child processes and zombie processes is set to theprocess ID of an implementation-dependent system process.That is, these processes are inherited by a special system process.<p><li>Each attached shared-memory segment is detached and the value of<i>shm_nattch</i>(see<i><a href="shmget.html">shmget()</a></i>)in the data structure associated with its shared memory IDis decremented by 1.<br><p><li>For each semaphore for which the calling process has set a<i>semadj</i>value, see<i><a href="semop.html">semop()</a></i>,that value is added to the<i>semval</i>of the specified semaphore.<p><li>If the process is a controlling process, the SIGHUPsignal will be sent to each process in the foreground process groupof the controlling terminal belonging to the calling process.<p><li>If the process is a controlling process, the controlling terminalassociated with the session is disassociated from the session, allowingit to be acquired by a new controlling process.<br><p><li>If the exit of theprocess causes a process group to become orphaned, and if any memberof the newly-orphaned process group is stopped, thena SIGHUP signal followed by a SIGCONTsignal will be sent to each process in the newly-orphaned process group.<p><li>If the Semaphores option is supported, all open named semaphoresin the calling process are closed as if by appropriate calls to<i><a href="sem_close.html">sem_close()</a></i>.<p><li>If the Process Memory Locking option is supported,any memory locks established by the 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<i>_exit()</i>.<p><li>Memory mappings created in the process are unmappedbefore the process is destroyed.<p><li>If the Message Passing option is supported,all open message queue descriptors in the calling process areclosed as if by appropriate calls to<i><a href="mq_close.html">mq_close()</a></i>.<p><li>If the Asynchronous Input and Output option is supportedany outstanding cancelable asynchronous I/O operations may becanceled.Those asynchronous I/O operations that are not canceled will completeas if the<i>_exit()</i>operation had not yet occurred,but any associated signal notifications will be suppressed.The<i>_exit()</i>operation itself may block awaiting such I/O completion.Whether any I/O is cancelled, and which I/O may be cancelled upon<i>_exit()</i>,is implementation-dependent.<p><li>Threads terminated by a call to<i>_exit()</i>will not invoke their cancellation cleanup handlers or per-thread datadestructors.<p></ul></blockquote><h4><a name = "tag_000_004_068"> </a>RETURN VALUE</h4><blockquote>These functions do not return.</blockquote><h4><a name = "tag_000_004_069"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_004_070"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_004_071"> </a>APPLICATION USAGE</h4><blockquote>Normally applications should use<i>exit()</i>rather than<i>_exit()</i>.</blockquote><h4><a name = "tag_000_004_072"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_004_073"> </a>SEE ALSO</h4><blockquote><i><a href="atexit.html">atexit()</a></i>,<i><a href="close.html">close()</a></i>,<i><a href="fclose.html">fclose()</a></i>,<i><a href="semop.html">semop()</a></i>,<i><a href="shmget.html">shmget()</a></i>,<i><a href="sigaction.html">sigaction()</a></i>,<i><a href="wait.html">wait()</a></i>,<i><a href="wait3.html">wait3()</a></i>,<i><a href="waitid.html">waitid()</a></i>,<i><a href="waitpid.html">waitpid()</a></i>,<i><a href="stdlib.h.html"><stdlib.h></a></i>,<i><a href="unistd.h.html"><unistd.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 1 of the SVID.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -