---
name: "explain_exit"
section: "3"
platform: "linux"
package: "libexplain-dev"
version: "1.4.D001-16"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/explain_exit"
---

# explain\_exit(3)

print an explanation of exit status before exiting

## NAME

explain\_exit - print an explanation of exit status before exiting

## SYNOPSIS

\#include \<libexplain/libexplain.h\>

void explain\_exit\_on\_exit(void);\
 void explain\_exit\_on\_error(void);\
 void explain\_exit\_cancel(void);

## DESCRIPTION

The *explain\_exit\_on\_exit* function may be used to have the calling program print an explanation of its exit status (the value passed to [*exit*(3)](/exit/3.md) or the return value from *main*) immediately before it terminates.

The *explain\_exit\_on\_error* function may be used to have the calling program print an explanation of its exit status immediately before it terminates, if that exit status is not EXIT\_SUCCESS.

The *explain\_exit\_cancel* function may be used to cancel the effect of the *explain\_exit\_on\_exit* or *explain\_exit\_on\_error* function.

These functions may be called multiple times, and in any order.  The last called has precedence.  The explanation will never be printed more than once.

### Call Exit As Normal

In order to have the explanation printed, simply call [*exit*(3)](/exit/3.md) as normal, or return from *main* as normal. Do not call any of these functions in order to exit your program, they are called before you exit your program.

### Caveat

This functionality is only available on systems with the [*on\_exit*(3)](/on_exit/3.md) system call. Unfortunately, the [*atexit*(3)](/atexit/3.md) system call is not sufficiently capable, as it does not pass the exit status to the registered function.

## SEE ALSO

- [*exit*(3)](/exit/3.md)

  cause normal process termination

- [*atexit*(3)](/atexit/3.md)

  register a function to be called at normal process termination

- [*on\_exit*(3)](/on_exit/3.md)

  register a function to be called at normal process termination

## COPYRIGHT

libexplain version 1.4\
 Copyright (C) 2009 Peter Miller

## AUTHOR

Written by Peter Miller \<pmiller@opensource.org.au\>
