Blob


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