1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
.TH EXITS 3
.SH NAME
exits, _exits, atexit, atexitdont, terminate \- terminate process, process cleanup
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.PP
.nf
.B
void _exits(char *msg)
.B
void exits(char *msg)
.PP
.B
int atexit(void(*)(void))
.PP
.B
void atexitdont(void(*)(void))
.fi
.SH DESCRIPTION
.I Exits
is the conventional way to terminate a process.
.I _Exits
also terminates a process but does not call the registered
.I atexit
handlers
.RI ( q.v. ).
They
can never return.
.PP
.I Msg
conventionally includes a brief (maximum length
.BR ERRLEN )
explanation of the reason for
exiting, or a null pointer or empty string to indicate normal termination.
The string is passed to the parent process, prefixed by the name and process
id of the exiting process, when the parent does a
.IR wait (3).
.PP
Before calling
.I _exits
with
.I msg
as an argument,
.I exits
calls in reverse order all the functions
recorded by
.IR atexit .
.PP
.I Atexit
records
.I fn
as a function to be called by
.IR exits .
It returns zero if it failed,
nonzero otherwise.
A typical use is to register a cleanup routine for an I/O package.
To simplify programs that fork or share memory,
.I exits
only calls those
.IR atexit -registered
functions that were registered by the same
process as that calling
.IR exits .
.PP
Calling
.I atexit
twice (or more) with the same function argument causes
.I exits
to invoke the function twice (or more).
.PP
There is a limit to the number of exit functions
that will be recorded;
.I atexit
returns 0 if that limit has been reached.
.PP
.I Atexitdont
cancels a previous registration of an exit function.
.SH SOURCE
.B \*9/src/lib9/atexit.c
.br
.B \*9/src/lib9/_exits.c
.SH "SEE ALSO"
.IR fork (2),
.IR wait (3)
.SH BUGS
Because of limitations of Unix, the exit status of a
process can only be an 8-bit integer.
Exit status 0 is used for empty exit messages, and 1 for
non-empty messages.
.PP
Exit codes 97 through 99 are used by the thread library to signal
internal synchronization errors between the main program
and a proxy process that implements backgrounding.
|