atexit(3) Library Functions Manual atexit(3) JMENO atexit - registruje funkci, ktera se ma vyvolat pri ukonceni procesu KNIHOVNA Standardni knihovna C (libc, -lc) POUZITI #include int atexit(void (*function)(void)); POPIS Funkce atexit() zaradi function do seznamu funkci, ktere jsou vyvolany pri normalnim ukonceni programu, at uz funkci exit(3) nebo navratem z funkce main. Funkce takto registrovane jsou volany v obracenem poradi jejich registrace; nejsou jim poskytnuty zadne argumenty. The same function may be registered multiple times: it is called once for each registration. POSIX.1 vyzaduje, aby implementace dovolovala minimalne ATEXIT_MAX(32) registraci takovychto funkci. Skutecny pocet moznych registraci podporovanych v dane implementaci je mozne zjistit pomoci sysconf(3). Pri vytvoreni procesu pomoci fork(2), zdedi potomek registrace svych rodicu. Pri uspesnem volani funkce exec(3), jsou vsechny registrace odstraneny. NAVRATOVE HODNOTY Funkce atexit() vraci hodnotu 0, byla-li uspesna, jinak je vracena nenulova hodnota. ATRIBUTY Vysvetleni pojmu pouzitych v teto casti viz attributes(7). +--------------------------------------------+---------------+---------+ |Rozhrani | Atribut | Hodnota | +--------------------------------------------+---------------+---------+ |atexit() | Thread safety | MT-Safe | +--------------------------------------------+---------------+---------+ VERZE POSIX.1 says that the result of calling exit(3) more than once (i.e., calling exit(3) within a function registered using atexit()) is undefined. On some systems (but not Linux), this can result in an infinite recursion; portable programs should not invoke exit(3) inside a function registered using atexit(). STANDARDY C11, POSIX.1-2008. HISTORIE POSIX.1-2001, C89, C99, SVr4, 4.3BSD. POZNAMKY Funkce registrovane pomoci atexit() (a on_exit(3)) nejsou volany, pokud je proces abnormalne ukoncen, napriklad kvuli doruceni signalu. If one of the registered functions calls _exit(2), then any remaining functions are not invoked, and the other process termination steps performed by exit(3) are not performed. The atexit() and on_exit(3) functions register functions on the same list: at normal process termination, the registered functions are invoked in reverse order of their registration by these two functions. According to POSIX.1, the result is undefined if longjmp(3) is used to terminate execution of one of the functions registered using atexit(). Linuxova poznamka Od verze glibc 2.2.3, mohou byt atexit() (a on_exit(3)) pouzity uvnitr sdilenych knihoven, aby spoustely funkce, ktere jsou volany, je-li knihovna uvolnena z pameti. PRIKLADY #include #include #include void bye(void) { printf("That was all, folks\n"); } int main(void) { long a; int i; a = sysconf(_SC_ATEXIT_MAX); printf("ATEXIT_MAX = %ld\n", a); i = atexit(bye); if (i != 0) { fprintf(stderr, "cannot set exit function\n"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } DALSI INFORMACE _exit(2), dlopen(3), exit(3), on_exit(3) PREKLAD Preklad teto prirucky do spanelstiny vytvorili Pavel Heimlich Tento preklad je bezplatna dokumentace; Prectete si GNU General Public License Version 3 nebo novejsi ohledne podminek autorskych prav. Neexistuje ZADNA ODPOVEDNOST. Pokud narazite na nejake chyby v prekladu teto prirucky, poslete e-mail na adresu . Linux man-pages 6.06 31. rijna 2023 atexit(3)