2004-04-10 18:53:55 +00:00
|
|
|
.TH EXITS 3
|
|
|
|
.SH NAME
|
2006-02-14 19:39:30 +00:00
|
|
|
exits, _exits, exitcode, atexit, atexitdont \- terminate process, process cleanup
|
2004-04-10 18:53:55 +00:00
|
|
|
.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
|
2006-02-14 19:39:30 +00:00
|
|
|
int exitcode(char *msg)
|
|
|
|
.PP
|
|
|
|
.B
|
2004-04-10 18:53:55 +00:00
|
|
|
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
|
2005-01-03 06:40:20 +00:00
|
|
|
also terminates a process but does not call the registered
|
|
|
|
.I atexit
|
|
|
|
handlers
|
|
|
|
.RI ( q.v. ).
|
2004-04-10 18:53:55 +00:00
|
|
|
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
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR wait (3) .
|
2004-04-10 18:53:55 +00:00
|
|
|
.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
|
2005-01-11 17:37:33 +00:00
|
|
|
.B \*9/src/lib9/atexit.c
|
2005-01-03 06:40:20 +00:00
|
|
|
.br
|
2005-01-11 17:37:33 +00:00
|
|
|
.B \*9/src/lib9/_exits.c
|
2004-04-10 18:53:55 +00:00
|
|
|
.SH "SEE ALSO"
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR fork (2) ,
|
|
|
|
.MR wait (3)
|
2005-01-03 06:40:20 +00:00
|
|
|
.SH BUGS
|
|
|
|
Because of limitations of Unix, the exit status of a
|
|
|
|
process can only be an 8-bit integer.
|
2006-02-14 19:39:30 +00:00
|
|
|
.I Exits
|
|
|
|
and
|
|
|
|
.I _exits
|
|
|
|
treat null or empty exit status as exit code 0
|
|
|
|
and call
|
|
|
|
.I exitcode
|
|
|
|
to translate any other string into an exit code.
|
|
|
|
By default, the library provides an
|
|
|
|
.I exitcode
|
|
|
|
that maps all messages to 1.
|
|
|
|
Applications may find it useful to provide their own
|
|
|
|
implementations of
|
|
|
|
.I exitcode .
|
2005-01-03 06:40:20 +00:00
|
|
|
.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.
|
2005-01-13 04:49:19 +00:00
|
|
|
.PP
|
|
|
|
To avoid name conflicts with the underlying system,
|
|
|
|
.I atexit
|
|
|
|
and
|
|
|
|
.I atexitdont
|
|
|
|
are preprocessor macros defined as
|
|
|
|
.I p9atexit
|
|
|
|
and
|
|
|
|
.IR p9atexitdont ;
|
|
|
|
see
|
2020-08-16 00:07:38 +00:00
|
|
|
.MR intro (3) .
|