Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

quick_exit — terminate with separate handlers

quick_exit terminates the program after invoking at_quick_exit handlers, skipping atexit handlers. It never returns to its caller.

Version: C23; repository compiler flag, production runtime not attested

Syntax

#include <stdlib.h>
[[noreturn]] void quick_exit(int status);

quick_exit(status) from <stdlib.h> invokes handlers registered with at_quick_exit in reverse registration order, then calls _Exit(status). It never returns. Registration returns zero on success.

Unlike exit, it skips atexit handlers; _Exit alone skips both groups. Buffer flushing, stream closing, and temporary-file removal are implementation-defined here. Write necessary data explicitly. EXIT_SUCCESS indicates success; EXIT_FAILURE indicates failure.

Repeated quick_exit, combining it with exit, a signal occurring during quick_exit, or escaping a handler through longjmp causes undefined behavior. The function does not invoke signal handlers.

Examples

#include <stdio.h>
#include <stdlib.h>

static void first(void)
{
    puts("first");
    fflush(stdout);
}

static void second(void)
{
    puts("second");
    fflush(stdout);
}

int main(void)
{
    if (at_quick_exit(first) != 0 || at_quick_exit(second) != 0) {
        return EXIT_FAILURE;
    }
    quick_exit(EXIT_SUCCESS);
}

Result

second
first

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources