1 cfa37a7b 2004-04-10 devnull .TH EXITS 3
3 cfa37a7b 2004-04-10 devnull exits, _exits, atexit, atexitdont, terminate \- terminate process, process cleanup
4 cfa37a7b 2004-04-10 devnull .SH SYNOPSIS
5 cfa37a7b 2004-04-10 devnull .B #include <u.h>
7 cfa37a7b 2004-04-10 devnull .B #include <libc.h>
11 cfa37a7b 2004-04-10 devnull void _exits(char *msg)
13 cfa37a7b 2004-04-10 devnull void exits(char *msg)
16 cfa37a7b 2004-04-10 devnull int atexit(void(*)(void))
19 cfa37a7b 2004-04-10 devnull void atexitdont(void(*)(void))
21 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
23 cfa37a7b 2004-04-10 devnull is the conventional way to terminate a process.
24 cfa37a7b 2004-04-10 devnull .I _Exits
25 058b0118 2005-01-03 devnull also terminates a process but does not call the registered
26 058b0118 2005-01-03 devnull .I atexit
28 058b0118 2005-01-03 devnull .RI ( q.v. ).
30 cfa37a7b 2004-04-10 devnull can never return.
33 cfa37a7b 2004-04-10 devnull conventionally includes a brief (maximum length
34 cfa37a7b 2004-04-10 devnull .BR ERRLEN )
35 cfa37a7b 2004-04-10 devnull explanation of the reason for
36 cfa37a7b 2004-04-10 devnull exiting, or a null pointer or empty string to indicate normal termination.
37 cfa37a7b 2004-04-10 devnull The string is passed to the parent process, prefixed by the name and process
38 cfa37a7b 2004-04-10 devnull id of the exiting process, when the parent does a
39 bf8a59fa 2004-04-11 devnull .IR wait (3).
41 cfa37a7b 2004-04-10 devnull Before calling
42 cfa37a7b 2004-04-10 devnull .I _exits
45 cfa37a7b 2004-04-10 devnull as an argument,
47 cfa37a7b 2004-04-10 devnull calls in reverse order all the functions
48 cfa37a7b 2004-04-10 devnull recorded by
49 cfa37a7b 2004-04-10 devnull .IR atexit .
51 cfa37a7b 2004-04-10 devnull .I Atexit
54 cfa37a7b 2004-04-10 devnull as a function to be called by
55 cfa37a7b 2004-04-10 devnull .IR exits .
56 cfa37a7b 2004-04-10 devnull It returns zero if it failed,
57 cfa37a7b 2004-04-10 devnull nonzero otherwise.
58 cfa37a7b 2004-04-10 devnull A typical use is to register a cleanup routine for an I/O package.
59 cfa37a7b 2004-04-10 devnull To simplify programs that fork or share memory,
61 cfa37a7b 2004-04-10 devnull only calls those
62 cfa37a7b 2004-04-10 devnull .IR atexit -registered
63 cfa37a7b 2004-04-10 devnull functions that were registered by the same
64 cfa37a7b 2004-04-10 devnull process as that calling
65 cfa37a7b 2004-04-10 devnull .IR exits .
68 cfa37a7b 2004-04-10 devnull .I atexit
69 cfa37a7b 2004-04-10 devnull twice (or more) with the same function argument causes
71 cfa37a7b 2004-04-10 devnull to invoke the function twice (or more).
73 cfa37a7b 2004-04-10 devnull There is a limit to the number of exit functions
74 cfa37a7b 2004-04-10 devnull that will be recorded;
75 cfa37a7b 2004-04-10 devnull .I atexit
76 cfa37a7b 2004-04-10 devnull returns 0 if that limit has been reached.
78 cfa37a7b 2004-04-10 devnull .I Atexitdont
79 cfa37a7b 2004-04-10 devnull cancels a previous registration of an exit function.
80 cfa37a7b 2004-04-10 devnull .SH SOURCE
81 c3674de4 2005-01-11 devnull .B \*9/src/lib9/atexit.c
83 c3674de4 2005-01-11 devnull .B \*9/src/lib9/_exits.c
84 cfa37a7b 2004-04-10 devnull .SH "SEE ALSO"
85 058b0118 2005-01-03 devnull .IR fork (2),
86 bf8a59fa 2004-04-11 devnull .IR wait (3)
88 058b0118 2005-01-03 devnull Because of limitations of Unix, the exit status of a
89 058b0118 2005-01-03 devnull process can only be an 8-bit integer.
90 058b0118 2005-01-03 devnull Exit status 0 is used for empty exit messages, and 1 for
91 058b0118 2005-01-03 devnull non-empty messages.
93 058b0118 2005-01-03 devnull Exit codes 97 through 99 are used by the thread library to signal
94 058b0118 2005-01-03 devnull internal synchronization errors between the main program
95 058b0118 2005-01-03 devnull and a proxy process that implements backgrounding.
97 c8b6342d 2005-01-13 devnull To avoid name conflicts with the underlying system,
98 c8b6342d 2005-01-13 devnull .I atexit
100 c8b6342d 2005-01-13 devnull .I atexitdont
101 c8b6342d 2005-01-13 devnull are preprocessor macros defined as
102 c8b6342d 2005-01-13 devnull .I p9atexit
104 c8b6342d 2005-01-13 devnull .IR p9atexitdont ;
106 c8b6342d 2005-01-13 devnull .IR intro (3).