1333 High kernel cpu usage & dtrace hang on idle system
[illumos-gate.git] / usr / src / man / man2 / exit.2
blob341b46c54b4427c245bc0089a958f055d6cbbeed
1 '\" te
2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" Copyright 1989 AT&T
4 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
5 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
6 .\" http://www.opengroup.org/bookstore/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
8 .\"  This notice shall appear on any product containing this material.
9 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
11 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
12 .TH EXIT 2 "Feb 5, 2008"
13 .SH NAME
14 exit, _Exit, _exit \- terminate process
15 .SH SYNOPSIS
16 .LP
17 .nf
18 #include <stdlib.h>
20 \fBvoid\fR \fBexit\fR(\fBint\fR \fIstatus\fR);
21 .fi
23 .LP
24 .nf
25 \fBvoid\fR \fB_Exit\fR(\fBint\fR \fIstatus\fR);
26 .fi
28 .LP
29 .nf
30 #include <unistd.h>
32 \fBvoid\fR \fB_exit\fR(\fBint\fR \fIstatus\fR);
33 .fi
35 .SH DESCRIPTION
36 .sp
37 .LP
38 The \fBexit()\fR function first calls all functions registered by
39 \fBatexit\fR(3C), in the reverse order of their registration, except that a
40 function is called after any previously registered functions that had already
41 been called at the time it was registered. Each function is called as many
42 times as it was registered. If, during the call to any such function, a call to
43 the \fBlongjmp\fR(3C) function is made that would terminate the call to the
44 registered function, the behavior is undefined.
45 .sp
46 .LP
47 If a function registered by a call to \fBatexit\fR(3C) fails to return, the
48 remaining registered functions are not called and the rest of the \fBexit()\fR
49 processing is not completed. If \fBexit()\fR is called more than once, the
50 effects are undefined.
51 .sp
52 .LP
53 The \fBexit()\fR function then flushes all open streams with unwritten buffered
54 data, closes all open streams, and removes all files created by
55 \fBtmpfile\fR(3C).
56 .sp
57 .LP
58 The \fB_Exit()\fR and \fB_exit()\fR functions are functionally equivalent. They
59 do not call functions registered with \fBatexit()\fR, do not call any
60 registered signal handlers, and do not flush open streams.
61 .sp
62 .LP
63 The \fB_exit()\fR, \fB_Exit()\fR, and \fBexit()\fR functions terminate the
64 calling process with the following consequences:
65 .RS +4
66 .TP
67 .ie t \(bu
68 .el o
69 All of the file descriptors, directory streams, conversion descriptors and
70 message catalogue descriptors open in the calling process are closed.
71 .RE
72 .RS +4
73 .TP
74 .ie t \(bu
75 .el o
76 If the parent process of the calling process is executing a \fBwait\fR(3C),
77 \fBwait3\fR(3C), \fBwaitid\fR(2), or \fBwaitpid\fR(3C), and has neither set its
78 \fBSA_NOCLDWAIT\fR flag nor set \fBSIGCHLD\fR to \fBSIG_IGN\fR, it is notified
79 of the calling process's termination and the low-order eight bits (that is,
80 bits 0377) of \fIstatus\fR are made available to it.  If the parent is not
81 waiting, the child's status will be made available to it when the parent
82 subsequently executes \fBwait()\fR, \fBwait3()\fR, \fBwaitid()\fR, or
83 \fBwaitpid()\fR.
84 .RE
85 .RS +4
86 .TP
87 .ie t \(bu
88 .el o
89 If the parent process of the calling process is not executing a \fBwait()\fR,
90 \fBwait3()\fR, \fBwaitid()\fR, or \fBwaitpid()\fR, and has not set its
91 \fBSA_NOCLDWAIT\fR flag, or set \fBSIGCHLD\fR to \fBSIG_IGN\fR, the calling
92 process is transformed into a \fIzombie process\fR. A \fIzombie process\fR is
93 an inactive process and it will be deleted at some later time when its parent
94 process executes \fBwait()\fR, \fBwait3()\fR, \fBwaitid()\fR, or
95 \fBwaitpid()\fR. A zombie process only occupies a slot in the process table; it
96 has no other space allocated either in user or kernel space. The process table
97 slot that it occupies is partially overlaid with time accounting information
98 (see \fB<sys/proc.h>\fR) to be used by the \fBtimes\fR(2) function.
99 .RE
100 .RS +4
102 .ie t \(bu
103 .el o
104 Termination of a process does not directly terminate its children. The sending
105 of a \fBSIGHUP\fR signal as described below indirectly terminates children in
106 some circumstances.
108 .RS +4
110 .ie t \(bu
111 .el o
112 A \fBSIGCHLD\fR will be sent to the parent process.
114 .RS +4
116 .ie t \(bu
117 .el o
118 The parent process \fBID\fR of all of the calling process's existing child
119 processes and zombie processes is set to 1. That is, these processes are
120 inherited by the initialization process (see \fBIntro\fR(2)).
122 .RS +4
124 .ie t \(bu
125 .el o
126 Each mapped memory object is unmapped.
128 .RS +4
130 .ie t \(bu
131 .el o
132 Each attached shared-memory segment is detached and the value of
133 \fBshm_nattch\fR (see \fBshmget\fR(2)) in the data structure associated with
134 its shared memory \fBID\fR is decremented by 1.
136 .RS +4
138 .ie t \(bu
139 .el o
140 For each semaphore for which the calling process has set a \fBsemadj\fR value
141 (see \fBsemop\fR(2)), that value is added to the \fBsemval\fR of the specified
142 semaphore.
144 .RS +4
146 .ie t \(bu
147 .el o
148 If the process is a controlling process, the \fBSIGHUP\fR signal will be sent
149 to each process in the foreground process group of the controlling terminal
150 belonging to the calling process.
152 .RS +4
154 .ie t \(bu
155 .el o
156 If the process is a controlling process, the controlling terminal associated
157 with the session is disassociated from the session, allowing it to be acquired
158 by a new controlling process.
160 .RS +4
162 .ie t \(bu
163 .el o
164 If the exit of the process causes a process group to become orphaned, and if
165 any member of the newly-orphaned process group is stopped, then a \fBSIGHUP\fR
166 signal followed by a \fBSIGCONT\fR signal will be sent to each process in the
167 newly-orphaned process group.
169 .RS +4
171 .ie t \(bu
172 .el o
173 If the parent process has set its \fBSA_NOCLDWAIT\fR flag, or set \fBSIGCHLD\fR
174 to \fBSIG_IGN\fR, the status will be discarded, and the lifetime of the calling
175 process will end immediately.
177 .RS +4
179 .ie t \(bu
180 .el o
181 If the process has process, text or data locks, an \fBUNLOCK\fR is performed
182 (see \fBplock\fR(3C) and \fBmemcntl\fR(2)).
184 .RS +4
186 .ie t \(bu
187 .el o
188 All open named semaphores in the process are closed as if by appropriate calls
189 to \fBsem_close\fR(3C). All open message queues in the process are closed as if
190 by appropriate calls to \fBmq_close\fR(3C). Any outstanding asynchronous I/O
191 operations may be cancelled.
193 .RS +4
195 .ie t \(bu
196 .el o
197 An accounting record is written on the accounting file if the system's
198 accounting routine is enabled (see \fBacct\fR(2)).
200 .RS +4
202 .ie t \(bu
203 .el o
204 An extended accounting record is written to the extended process accounting
205 file if the system's extended process accounting facility is enabled (see
206 \fBacctadm\fR(1M)).
208 .RS +4
210 .ie t \(bu
211 .el o
212 If the current process is the last process within its task and if the system's
213 extended task accounting facility is enabled (see \fBacctadm\fR(1M)), an
214 extended accounting record is written to the extended task accounting file.
216 .SH RETURN VALUES
219 These functions do not return.
220 .SH ERRORS
223 No errors are defined.
224 .SH USAGE
227 Normally applications should use \fBexit()\fR rather than \fB_exit()\fR.
228 .SH ATTRIBUTES
231 See \fBattributes\fR(5) for descriptions of the following attributes:
236 box;
237 c | c
238 l | l .
239 ATTRIBUTE TYPE  ATTRIBUTE VALUE
241 Interface Stability     Committed
243 MT-Level        See below.
245 Standard        See \fBstandards\fR(5).
250 The \fB_exit()\fR and \fB_Exit()\fR functions are Async-Signal-Safe.
251 .SH SEE ALSO
254 \fBacctadm\fR(1M), \fBIntro\fR(2), \fBacct\fR(2), \fBclose\fR(2),
255 \fBmemcntl\fR(2), \fBsemop\fR(2), \fBshmget\fR(2), \fBsigaction\fR(2),
256 \fBtimes\fR(2), \fBwaitid\fR(2), \fBatexit\fR(3C), \fBfclose\fR(3C),
257 \fBmq_close\fR(3C), \fBplock\fR(3C), \fBsignal.h\fR(3HEAD), \fBtmpfile\fR(3C),
258 \fBwait\fR(3C), \fBwait3\fR(3C), \fBwaitpid\fR(3C), \fBattributes\fR(5),
259 \fBstandards\fR(5)