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