1 cfa37a7b 2004-04-10 devnull .TH EXITS 3
3 3449b189 2006-02-14 devnull exits, _exits, exitcode, atexit, atexitdont \- 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 3449b189 2006-02-14 devnull int exitcode(char *msg)
19 cfa37a7b 2004-04-10 devnull int atexit(void(*)(void))
22 cfa37a7b 2004-04-10 devnull void atexitdont(void(*)(void))
24 cfa37a7b 2004-04-10 devnull .SH DESCRIPTION
26 cfa37a7b 2004-04-10 devnull is the conventional way to terminate a process.
27 cfa37a7b 2004-04-10 devnull .I _Exits
28 058b0118 2005-01-03 devnull also terminates a process but does not call the registered
29 058b0118 2005-01-03 devnull .I atexit
31 058b0118 2005-01-03 devnull .RI ( q.v. ).
33 cfa37a7b 2004-04-10 devnull can never return.
36 cfa37a7b 2004-04-10 devnull conventionally includes a brief (maximum length
37 cfa37a7b 2004-04-10 devnull .BR ERRLEN )
38 cfa37a7b 2004-04-10 devnull explanation of the reason for
39 cfa37a7b 2004-04-10 devnull exiting, or a null pointer or empty string to indicate normal termination.
40 cfa37a7b 2004-04-10 devnull The string is passed to the parent process, prefixed by the name and process
41 cfa37a7b 2004-04-10 devnull id of the exiting process, when the parent does a
42 bf8a59fa 2004-04-11 devnull .IR wait (3).
44 cfa37a7b 2004-04-10 devnull Before calling
45 cfa37a7b 2004-04-10 devnull .I _exits
48 cfa37a7b 2004-04-10 devnull as an argument,
50 cfa37a7b 2004-04-10 devnull calls in reverse order all the functions
51 cfa37a7b 2004-04-10 devnull recorded by
52 cfa37a7b 2004-04-10 devnull .IR atexit .
54 cfa37a7b 2004-04-10 devnull .I Atexit
57 cfa37a7b 2004-04-10 devnull as a function to be called by
58 cfa37a7b 2004-04-10 devnull .IR exits .
59 cfa37a7b 2004-04-10 devnull It returns zero if it failed,
60 cfa37a7b 2004-04-10 devnull nonzero otherwise.
61 cfa37a7b 2004-04-10 devnull A typical use is to register a cleanup routine for an I/O package.
62 cfa37a7b 2004-04-10 devnull To simplify programs that fork or share memory,
64 cfa37a7b 2004-04-10 devnull only calls those
65 cfa37a7b 2004-04-10 devnull .IR atexit -registered
66 cfa37a7b 2004-04-10 devnull functions that were registered by the same
67 cfa37a7b 2004-04-10 devnull process as that calling
68 cfa37a7b 2004-04-10 devnull .IR exits .
71 cfa37a7b 2004-04-10 devnull .I atexit
72 cfa37a7b 2004-04-10 devnull twice (or more) with the same function argument causes
74 cfa37a7b 2004-04-10 devnull to invoke the function twice (or more).
76 cfa37a7b 2004-04-10 devnull There is a limit to the number of exit functions
77 cfa37a7b 2004-04-10 devnull that will be recorded;
78 cfa37a7b 2004-04-10 devnull .I atexit
79 cfa37a7b 2004-04-10 devnull returns 0 if that limit has been reached.
81 cfa37a7b 2004-04-10 devnull .I Atexitdont
82 cfa37a7b 2004-04-10 devnull cancels a previous registration of an exit function.
83 cfa37a7b 2004-04-10 devnull .SH SOURCE
84 c3674de4 2005-01-11 devnull .B \*9/src/lib9/atexit.c
86 c3674de4 2005-01-11 devnull .B \*9/src/lib9/_exits.c
87 cfa37a7b 2004-04-10 devnull .SH "SEE ALSO"
88 058b0118 2005-01-03 devnull .IR fork (2),
89 bf8a59fa 2004-04-11 devnull .IR wait (3)
91 058b0118 2005-01-03 devnull Because of limitations of Unix, the exit status of a
92 058b0118 2005-01-03 devnull process can only be an 8-bit integer.
95 3449b189 2006-02-14 devnull .I _exits
96 3449b189 2006-02-14 devnull treat null or empty exit status as exit code 0
98 3449b189 2006-02-14 devnull .I exitcode
99 3449b189 2006-02-14 devnull to translate any other string into an exit code.
100 3449b189 2006-02-14 devnull By default, the library provides an
101 3449b189 2006-02-14 devnull .I exitcode
102 3449b189 2006-02-14 devnull that maps all messages to 1.
103 3449b189 2006-02-14 devnull Applications may find it useful to provide their own
104 3449b189 2006-02-14 devnull implementations of
105 3449b189 2006-02-14 devnull .I exitcode .
107 058b0118 2005-01-03 devnull Exit codes 97 through 99 are used by the thread library to signal
108 058b0118 2005-01-03 devnull internal synchronization errors between the main program
109 058b0118 2005-01-03 devnull and a proxy process that implements backgrounding.
111 c8b6342d 2005-01-13 devnull To avoid name conflicts with the underlying system,
112 c8b6342d 2005-01-13 devnull .I atexit
114 c8b6342d 2005-01-13 devnull .I atexitdont
115 c8b6342d 2005-01-13 devnull are preprocessor macros defined as
116 c8b6342d 2005-01-13 devnull .I p9atexit
118 c8b6342d 2005-01-13 devnull .IR p9atexitdont ;
120 c8b6342d 2005-01-13 devnull .IR intro (3).