logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

_Exit.3p (16148B)


  1. '\" et
  2. .TH _EXIT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. _Exit,
  12. _exit
  13. \(em terminate a process
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <stdlib.h>
  18. .P
  19. void _Exit(int \fIstatus\fP);
  20. .P
  21. #include <unistd.h>
  22. .P
  23. void _exit(int \fIstatus\fP);
  24. .fi
  25. .SH DESCRIPTION
  26. For
  27. \fI_Exit\fR():
  28. The functionality described on this reference page is aligned with the
  29. ISO\ C standard. Any conflict between the requirements described here and the
  30. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  31. .P
  32. The value of
  33. .IR status
  34. may be 0, EXIT_SUCCESS, EXIT_FAILURE,
  35. or any other value, though only the least significant 8 bits (that is,
  36. .IR status
  37. & 0377) shall be available from
  38. \fIwait\fR()
  39. and
  40. \fIwaitpid\fR();
  41. the full value shall be available from
  42. \fIwaitid\fR()
  43. and in the
  44. .BR siginfo_t
  45. passed to a signal handler for SIGCHLD.
  46. .P
  47. The
  48. \fI_Exit\fR()
  49. and
  50. \fI_exit\fR()
  51. functions shall be functionally equivalent.
  52. .P
  53. The
  54. \fI_Exit\fR()
  55. and
  56. \fI_exit\fR()
  57. functions shall not call functions registered with
  58. \fIatexit\fR()
  59. nor any registered signal handlers.
  60. Open streams shall not be flushed.
  61. Whether open streams are closed (without flushing) is
  62. implementation-defined. Finally, the calling process shall be
  63. terminated with the consequences described below.
  64. .SS "Consequences of Process Termination"
  65. .P
  66. Process termination caused by any reason shall have the following
  67. consequences:
  68. .TP 10
  69. .BR Note:
  70. These consequences are all extensions to the ISO\ C standard and are not further
  71. CX shaded. However, functionality relating to the XSI option is shaded.
  72. .P
  73. .IP " *" 4
  74. All of the file descriptors, directory streams, conversion descriptors,
  75. and message catalog descriptors open in the calling process shall
  76. be closed.
  77. .IP " *" 4
  78. If the parent process of the calling process has set its SA_NOCLDWAIT
  79. flag or has set the action for the SIGCHLD signal to SIG_IGN:
  80. .RS 4
  81. .IP -- 4
  82. The process' status information (see
  83. .IR "Section 2.13" ", " "Status Information"),
  84. if any, shall be discarded.
  85. .IP -- 4
  86. The lifetime of the calling process shall end immediately. If
  87. SA_NOCLDWAIT is set, it is implementation-defined whether a SIGCHLD
  88. signal is sent to the parent process.
  89. .IP -- 4
  90. If a thread in the parent process of the calling process is blocked in
  91. \fIwait\fR(),
  92. \fIwaitpid\fR(),
  93. or
  94. \fIwaitid\fR(),
  95. and the parent process has no remaining child processes in the
  96. set of waited-for children, the
  97. \fIwait\fR(),
  98. \fIwaitid\fR(),
  99. or
  100. \fIwaitpid\fR()
  101. function shall fail and set
  102. .IR errno
  103. to
  104. .BR [ECHILD] .
  105. .P
  106. Otherwise:
  107. .IP -- 4
  108. Status information (see
  109. .IR "Section 2.13" ", " "Status Information")
  110. shall be generated.
  111. .IP -- 4
  112. The calling process shall be transformed into a zombie process. Its
  113. status information shall be made available to the parent process
  114. until the process' lifetime ends.
  115. .IP -- 4
  116. The process' lifetime shall end once its parent obtains the process'
  117. status information via a currently-blocked or future call to
  118. \fIwait\fR(),
  119. \fIwaitid\fR()
  120. (without WNOWAIT), or
  121. \fIwaitpid\fR().
  122. .IP -- 4
  123. If one or more threads in the parent process of the calling process is
  124. blocked in a call to
  125. \fIwait\fR(),
  126. \fIwaitid\fR(),
  127. or
  128. \fIwaitpid\fR()
  129. awaiting termination of the process, one (or, if any are calling
  130. \fIwaitid\fR()
  131. with WNOWAIT, possibly more) of these threads shall obtain the
  132. process' status information as specified in
  133. .IR "Section 2.13" ", " "Status Information"
  134. and become unblocked.
  135. .IP -- 4
  136. A SIGCHLD shall be sent to the parent process.
  137. .RE
  138. .IP " *" 4
  139. Termination of a process does not directly terminate its children.
  140. The sending of a SIGHUP signal as described below indirectly
  141. terminates children in some circumstances.
  142. .IP " *" 4
  143. The parent process ID of all of the existing child processes and
  144. zombie processes of the calling process shall be set to the process ID
  145. of an implementation-defined system process. That is, these processes
  146. shall be inherited by a special system process.
  147. .IP " *" 4
  148. Each attached shared-memory segment is detached and the value of
  149. .IR shm_nattch
  150. (see
  151. \fIshmget\fR())
  152. in the data structure associated with its shared memory ID
  153. shall be decremented by 1.
  154. .IP " *" 4
  155. For each semaphore for which the calling process has set a
  156. .IR semadj
  157. value (see
  158. \fIsemop\fR()),
  159. that value shall be added to the
  160. .IR semval
  161. of the specified semaphore.
  162. .IP " *" 4
  163. If the process is a controlling process, the SIGHUP
  164. signal shall be sent to each process in the foreground process group of
  165. the controlling terminal belonging to the calling process.
  166. .IP " *" 4
  167. If the process is a controlling process, the controlling terminal
  168. associated with the session shall be disassociated from the session,
  169. allowing it to be acquired by a new controlling process.
  170. .IP " *" 4
  171. If the exit of the process causes a process group to become orphaned,
  172. and if any member of the newly-orphaned process group is stopped, then
  173. a SIGHUP signal followed by a SIGCONT signal shall be sent to each
  174. process in the newly-orphaned process group.
  175. .IP " *" 4
  176. All open named semaphores in the calling process shall be closed as
  177. if by appropriate calls to
  178. \fIsem_close\fR().
  179. .IP " *" 4
  180. Any memory locks established by the process via calls to
  181. \fImlockall\fR()
  182. or
  183. \fImlock\fR()
  184. shall be removed. If locked pages in the address space of the calling
  185. process are also mapped into the address spaces of other processes and
  186. are locked by those processes, the locks established by the other
  187. processes shall be unaffected by the call by this process to
  188. \fI_Exit\fR()
  189. or
  190. \fI_exit\fR().
  191. .IP " *" 4
  192. Memory mappings that were created in the process shall be unmapped
  193. before the process is destroyed.
  194. .IP " *" 4
  195. Any blocks of typed memory that were mapped in the calling process
  196. shall be unmapped, as if
  197. \fImunmap\fR()
  198. was implicitly called to unmap them.
  199. .IP " *" 4
  200. All open message queue descriptors in the calling process shall be
  201. closed as if by appropriate calls to
  202. \fImq_close\fR().
  203. .IP " *" 4
  204. Any outstanding cancelable asynchronous I/O operations may be
  205. canceled. Those asynchronous I/O operations that are not canceled
  206. shall complete as if the
  207. \fI_Exit\fR()
  208. or
  209. \fI_exit\fR()
  210. operation had not yet occurred, but any associated signal notifications
  211. shall be suppressed. The
  212. \fI_Exit\fR()
  213. or
  214. \fI_exit\fR()
  215. operation may block awaiting such I/O completion. Whether any
  216. I/O is canceled, and which I/O may be canceled upon
  217. \fI_Exit\fR()
  218. or
  219. \fI_exit\fR(),
  220. is implementation-defined.
  221. .IP " *" 4
  222. Threads terminated by a call to
  223. \fI_Exit\fR()
  224. or
  225. \fI_exit\fR()
  226. shall not invoke their cancellation cleanup handlers or per-thread data
  227. destructors.
  228. .IP " *" 4
  229. If the calling process is a trace controller process, any trace streams
  230. that were created by the calling process shall be shut down as
  231. described by the
  232. \fIposix_trace_shutdown\fR()
  233. function, and mapping of trace event names to trace event type identifiers
  234. of any process built for these trace streams may be deallocated.
  235. .SH "RETURN VALUE"
  236. These functions do not return.
  237. .SH ERRORS
  238. No errors are defined.
  239. .LP
  240. .IR "The following sections are informative."
  241. .SH EXAMPLES
  242. None.
  243. .SH "APPLICATION USAGE"
  244. Normally applications should use
  245. \fIexit\fR()
  246. rather than
  247. \fI_Exit\fR()
  248. or
  249. \fI_exit\fR().
  250. .SH RATIONALE
  251. .SS "Process Termination"
  252. .P
  253. Early proposals drew a distinction between normal and abnormal process
  254. termination. Abnormal termination was caused only by certain signals
  255. and resulted in implementation-defined ``actions'', as discussed below.
  256. Subsequent proposals distinguished three types of termination:
  257. \fInormal termination\fP (as in the current specification), \fIsimple
  258. abnormal termination\fP, and \fIabnormal termination with actions\fP.
  259. Again the distinction between the two types of abnormal termination was
  260. that they were caused by different signals and that
  261. implementation-defined actions would result in the latter case. Given
  262. that these actions were completely implementation-defined, the early
  263. proposals were only saying when the actions could occur and how their
  264. occurrence could be detected, but not what they were. This was of
  265. little or no use to conforming applications, and thus the distinction is
  266. not made in this volume of POSIX.1\(hy2017.
  267. .P
  268. The implementation-defined actions usually include, in most
  269. historical implementations, the creation of a file named
  270. .BR core
  271. in the current working directory of the process. This file contains an
  272. image of the memory of the process, together with descriptive
  273. information about the process, perhaps sufficient to reconstruct the
  274. state of the process at the receipt of the signal.
  275. .P
  276. There is a potential security problem in creating a
  277. .BR core
  278. file if the process was set-user-ID
  279. and the current user is not the owner of the program, if the process
  280. was set-group-ID
  281. and none of the user's groups match the group of the program, or if the
  282. user does not have permission to write in the current directory. In
  283. this situation, an implementation either should not create a
  284. .BR core
  285. file or should make it unreadable by the user.
  286. .P
  287. Despite the silence of this volume of POSIX.1\(hy2017 on this feature, applications are
  288. advised not to create files named
  289. .BR core
  290. because of potential conflicts in many implementations. Some
  291. implementations use a name other than
  292. .BR core
  293. for the file; for example, by appending the process ID to the filename.
  294. .SS "Terminating a Process"
  295. .P
  296. It is important that the consequences of process termination as
  297. described occur regardless of whether the process called
  298. \fI_exit\fR()
  299. (perhaps indirectly through
  300. \fIexit\fR())
  301. or instead was terminated due to a signal or for some other reason.
  302. Note that in the specific case of
  303. \fIexit\fR()
  304. this means that the
  305. .IR status
  306. argument to
  307. \fIexit\fR()
  308. is treated in the same way as the
  309. .IR status
  310. argument to
  311. \fI_exit\fR().
  312. .P
  313. A language other than C may have other termination primitives than the
  314. C-language
  315. \fIexit\fR()
  316. function, and programs written in such a language should use its native
  317. termination primitives, but those should have as part of their function
  318. the behavior of
  319. \fI_exit\fR()
  320. as described. Implementations in languages other than C are outside
  321. the scope of this version of this volume of POSIX.1\(hy2017, however.
  322. .P
  323. As required by the ISO\ C standard, using
  324. .BR return
  325. from
  326. \fImain\fR()
  327. has the same behavior (other than with respect to language scope
  328. issues) as calling
  329. \fIexit\fR()
  330. with the returned value. Reaching the end of the
  331. \fImain\fR()
  332. function has the same behavior as calling
  333. .IR exit (0).
  334. .P
  335. A value of zero (or EXIT_SUCCESS, which is required to be zero)
  336. for the argument
  337. .IR status
  338. conventionally indicates successful termination. This corresponds to
  339. the specification for
  340. \fIexit\fR()
  341. in the ISO\ C standard. The convention is followed by utilities such as
  342. .IR make
  343. and various shells, which interpret a zero status
  344. from a child process as success. For this reason, applications should
  345. not call \fIexit\fP(0) or \fI_exit\fP(0) when they terminate
  346. unsuccessfully; for example, in signal-catching functions.
  347. .P
  348. Historically, the implementation-defined process that inherits
  349. children whose parents have terminated without waiting on them is
  350. called
  351. .IR init
  352. and has a process ID of 1.
  353. .P
  354. The sending of a SIGHUP
  355. to the foreground process group when a controlling process terminates
  356. corresponds to somewhat different historical implementations. In System
  357. V, the kernel sends a
  358. SIGHUP on termination of (essentially) a controlling process. In 4.2 BSD,
  359. the kernel does not send SIGHUP in a case like this, but the termination
  360. of a controlling process is usually noticed by a system daemon, which
  361. arranges to send a SIGHUP to the foreground process group with the
  362. \fIvhangup\fR()
  363. function. However, in 4.2 BSD, due to the behavior of the shells that
  364. support job control,
  365. the controlling process is usually a shell with no other processes in
  366. its process group. Thus, a change to make
  367. \fI_exit\fR()
  368. behave this way in such systems should not cause problems with existing
  369. applications.
  370. .P
  371. The termination of a process may cause a process group to become
  372. orphaned in either of two ways.
  373. The connection of a process group to its parent(s) outside of the group
  374. depends on both the parents and their children. Thus, a process group
  375. may be orphaned by the termination of the last connecting parent
  376. process outside of the group or by the termination of the last direct
  377. descendant of the parent process(es). In either case, if the
  378. termination of a process causes a process group to become orphaned,
  379. processes within the group are disconnected from their job control
  380. shell, which no longer has any information on the existence of the
  381. process group. Stopped processes within the group would languish
  382. forever. In order to avoid this problem, newly orphaned process groups
  383. that contain stopped processes are sent a SIGHUP signal and a SIGCONT
  384. signal to indicate that they have been disconnected from their
  385. session.
  386. The SIGHUP signal causes the process group members to terminate unless
  387. they are catching or ignoring SIGHUP. Under most circumstances, all of
  388. the members of the process group are stopped if any of them are
  389. stopped.
  390. .P
  391. The action of sending a SIGHUP and a SIGCONT signal to members of a
  392. newly orphaned process group is similar to the action of 4.2 BSD, which
  393. sends SIGHUP and SIGCONT to each stopped child of an exiting process.
  394. If such children exit in response to the SIGHUP, any additional
  395. descendants receive similar treatment at that time. In this volume of POSIX.1\(hy2017, the
  396. signals are sent to the entire process group at the same time. Also,
  397. in this volume of POSIX.1\(hy2017, but not in 4.2 BSD, stopped processes may be orphaned, but
  398. may be members of a process group that is not orphaned; therefore, the
  399. action taken at
  400. \fI_exit\fR()
  401. must consider processes other than child processes.
  402. .P
  403. It is possible for a process group to be orphaned by a call to
  404. \fIsetpgid\fR()
  405. or
  406. \fIsetsid\fR(),
  407. as well as by process termination. This volume of POSIX.1\(hy2017 does not require sending
  408. SIGHUP and SIGCONT in those cases, because, unlike process termination,
  409. those cases are not caused accidentally by applications that are
  410. unaware of job control. An implementation can choose to send SIGHUP
  411. and SIGCONT in those cases as an extension; such an extension must be
  412. documented as required in
  413. .IR <signal.h> .
  414. .P
  415. The ISO/IEC\ 9899:\|1999 standard adds the
  416. \fI_Exit\fR()
  417. function that results in immediate program termination without
  418. triggering signals or
  419. \fIatexit\fR()-registered
  420. functions. In POSIX.1\(hy2008, this is equivalent to the
  421. \fI_exit\fR()
  422. function.
  423. .SH "FUTURE DIRECTIONS"
  424. None.
  425. .SH "SEE ALSO"
  426. .IR "\fIatexit\fR\^(\|)",
  427. .IR "\fIexit\fR\^(\|)",
  428. .IR "\fImlock\fR\^(\|)",
  429. .IR "\fImlockall\fR\^(\|)",
  430. .IR "\fImq_close\fR\^(\|)",
  431. .IR "\fImunmap\fR\^(\|)",
  432. .IR "\fIposix_trace_create\fR\^(\|)",
  433. .IR "\fIsem_close\fR\^(\|)",
  434. .IR "\fIsemop\fR\^(\|)",
  435. .IR "\fIsetpgid\fR\^(\|)",
  436. .IR "\fIsetsid\fR\^(\|)",
  437. .IR "\fIshmget\fR\^(\|)",
  438. .IR "\fIwait\fR\^(\|)",
  439. .IR "\fIwaitid\fR\^(\|)"
  440. .P
  441. The Base Definitions volume of POSIX.1\(hy2017,
  442. .IR "\fB<stdlib.h>\fP",
  443. .IR "\fB<unistd.h>\fP"
  444. .\"
  445. .SH COPYRIGHT
  446. Portions of this text are reprinted and reproduced in electronic form
  447. from IEEE Std 1003.1-2017, Standard for Information Technology
  448. -- Portable Operating System Interface (POSIX), The Open Group Base
  449. Specifications Issue 7, 2018 Edition,
  450. Copyright (C) 2018 by the Institute of
  451. Electrical and Electronics Engineers, Inc and The Open Group.
  452. In the event of any discrepancy between this version and the original IEEE and
  453. The Open Group Standard, the original IEEE and The Open Group Standard
  454. is the referee document. The original Standard can be obtained online at
  455. http://www.opengroup.org/unix/online.html .
  456. .PP
  457. Any typographical or formatting errors that appear
  458. in this page are most likely
  459. to have been introduced during the conversion of the source files to
  460. man page format. To report such errors, see
  461. https://www.kernel.org/doc/man-pages/reporting_bugs.html .