{"id":7174,"date":"2022-12-20T19:35:43","date_gmt":"2022-12-20T22:35:43","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/atexit-man3\/"},"modified":"2022-12-20T19:35:43","modified_gmt":"2022-12-20T22:35:43","slug":"atexit-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/atexit-man3\/","title":{"rendered":"ATEXIT (man3)"},"content":{"rendered":"<h1 align=\"center\">ATEXIT<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ATTRIBUTES\">ATTRIBUTES<\/a><br \/> <a href=\"#CONFORMING TO\">CONFORMING TO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COLOPHON\">COLOPHON<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">atexit \u2212 register a function to be called at normal process termination<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>#include <stdlib.h><\/b><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>int atexit(void (*<\/b><i>function<\/i><b>)(void));<\/b><\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>atexit<\/b>() function registers the given <i>function<\/i> to be called at normal process termination, either via <b>exit<\/b>(3) or via return from the program\u2019s <i>main<\/i>(). Functions so registered are called in the reverse order of their registration; no arguments are passed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The same function may be registered multiple times: it is called once for each registration.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1 requires that an implementation allow at least <b>ATEXIT_MAX<\/b> (32) such functions to be registered. The actual limit supported by an implementation can be obtained using <b>sysconf<\/b>(3).<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">When a child process is created via <b>fork<\/b>(2), it inherits copies of its parent\u2019s registrations. Upon a successful call to one of the <b>exec<\/b>(3) functions, all registrations are removed.<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>atexit<\/b>() function returns the value 0 if successful; otherwise it returns a nonzero value.<\/p>\n<h2>ATTRIBUTES <a name=\"ATTRIBUTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">For an explanation of the terms used in this section, see <b>attributes<\/b>(7).<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"> <\/td>\n<td width=\"8%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"62%\"> <\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"8%\"> <\/td>\n<td width=\"8%\"><\/td>\n<td width=\"7%\"><\/td>\n<td width=\"62%\"> <\/td>\n<\/tr>\n<\/table>\n<p align=\"center\"><img decoding=\"async\" src=\"grohtml-1574081.png\" alt=\"Image grohtml-1574081.png\"><\/p>\n<h2>CONFORMING TO <a name=\"CONFORMING TO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Functions registered using <b>atexit<\/b>() (and <b>on_exit<\/b>(3)) are not called if a process terminates abnormally because of the delivery of a signal.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If one of the registered functions calls <b>_exit<\/b>(2), then any remaining functions are not invoked, and the other process termination steps performed by <b>exit<\/b>(3) are not performed.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">POSIX.1 says that the result of calling <b>exit<\/b>(3) more than once (i.e., calling <b>exit<\/b>(3) within a function registered using <b>atexit<\/b>()) is undefined. On some systems (but not Linux), this can result in an infinite recursion; portable programs should not invoke <b>exit<\/b>(3) inside a function registered using <b>atexit<\/b>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <b>atexit<\/b>() and <b>on_exit<\/b>(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.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">According to POSIX.1, the result is undefined if <b>longjmp<\/b>(3) is used to terminate execution of one of the functions registered using <b>atexit<\/b>().<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Linux notes<\/b> <br \/> Since glibc 2.2.3, <b>atexit<\/b>() (and <b>on_exit<\/b>(3)) can be used within a shared library to establish functions that are called when the shared library is unloaded.<\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <stdio.h> <br \/> #include <stdlib.h> <br \/> #include <unistd.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">void <br \/> bye(void) <br \/> { <br \/> printf(&#8220;That was all, folksn&#8221;); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int <br \/> main(void) <br \/> { <br \/> long a; <br \/> int i;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">a = sysconf(_SC_ATEXIT_MAX); <br \/> printf(&#8220;ATEXIT_MAX = %ldn&#8221;, a);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">i = atexit(bye); <br \/> if (i != 0) { <br \/> fprintf(stderr, &#8220;cannot set exit functionn&#8221;); <br \/> exit(EXIT_FAILURE); <br \/> }<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">exit(EXIT_SUCCESS); <br \/> }<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>_exit<\/b>(2), <b>dlopen<\/b>(3), <b>exit<\/b>(3), <b>on_exit<\/b>(3)<\/p>\n<h2>COLOPHON <a name=\"COLOPHON\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This page is part of release 5.10 of the Linux <i>man-pages<\/i> project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https:\/\/www.kernel.org\/doc\/man\u2212pages\/.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  atexit \u2212 register a function to be called at normal process termination <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2536],"tags":[2538,1993,3007],"class_list":["post-7174","post","type-post","status-publish","format-standard","hentry","category-3-llamadas-de-bibliotecas","tag-2538","tag-atexit","tag-man3"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7174","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7174"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7174\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}