<p>Is there any difference between</p>

<pre><code>   int on_exit(void (*function)(int , void *), void *arg);
</code></pre>

<p>and</p>

<pre><code>   int atexit(void (*function)(void));
</code></pre>

<p>other than the fact that the function used by on_exit gets the exit status?</p>

<p>That is, if I don't care about the exit status, is there any reason to use one or the other?</p>

<p><strong>Edit:</strong> Many of the answers warned against <code>on_exit</code> because it's non-standard. If I'm developing an app that is for internal corporate use and guaranteed to run on specific configurations, should I worry about this? </p>

[{'answer_id': 10684, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 4, 'selected': False, 'text': '<p>You should use <code>atexit()</code> if possible.  <code>on_exit()</code> is nonstandard and less common.  For example, it\'s not available on OS X.</p>\n\n<p>Kernel.org - <a href="http://www.kernel.org/doc/man-pages/online/pages/man3/on_exit.3.html" rel="noreferrer"><code>on_exit()</code></a>:</p>\n\n<blockquote>\n  <p>This function comes from SunOS 4, but is also present in libc4, libc5 and\n  glibc.  It no longer occurs in Solaris (SunOS 5).  Avoid this function, and\n  use the standard atexit(3) instead.</p>\n</blockquote>\n'}, {'answer_id': 10686, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 5, 'selected': True, 'text': '<p>According to <a href="http://www.delorie.com/gnu/docs/glibc/libc_560.html" rel="noreferrer">this link</a> I found, it seems there are a few differences.  <code>on_exit</code> will let you pass in an argument that is passed in to the <code>on_exit</code> function when it is called... which might let you set up some pointers to do some cleanup work on when it is time to exit.</p>\n\n<p>Furthermore, it appears that <code>on_exit</code> was a SunOS specific function that may not be compatible on all platforms... so you may want to stick with atexit, despite it being more restrictive.</p>\n'}, {'answer_id': 10770, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 0, 'selected': False, 'text': "<p>@Nathan</p>\n\n<p>First, see if there is another API call to determine exit status... a quick glance and I don't see one, but I am not well versed in the standard C API.</p>\n\n<p>An easy alternative is to have a global variable that stores the exit status... the default being an unknown error cause (for if the program terminates abnormally).  Then, when you call exit, you can store the exit status in the global and retrieve it from any atexit functions.  This requires storing the exit status diligently before every exit call, and clearly is not ideal, but if there is no API and you don't want to risk <code>on_exit</code> not being on the platform... it might be the only option.</p>\n"}, {'answer_id': 10796, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 1, 'selected': False, 'text': "<p>@Nathan, I can't find any function that will return the exit code for the current running process.  I expect that it isn't set yet at the point when <code>atexit()</code> is called, anyway.  By this I mean that the runtime knows what it is, but probably hasn't reported it to the OS.  This is pretty much just conjecture, though.</p>\n\n<p>It looks like you will either need to use <code>on_exit()</code> or structure your program so that the exit code doesn't matter.  It would not be unreasonable to have the last statement in your main function flip a global <code>exited_cleanly</code> variable to true.  In the function you register with <code>atexit()</code>, you could check this variable to determine how the program exited.  This will only give you two states, but I expect that would be sufficient for most needs.  You could also expand this type of scheme to support more exit states if necessary.</p>\n"}, {'answer_id': 3273116, 'author': 'R.. GitHub STOP HELPING ICE', 'author_id': 379897, 'author_profile': 'https://Stackoverflow.com/users/379897', 'pm_score': 3, 'selected': False, 'text': '<p>The difference is that <code>atexit</code> is C and <code>on_exit</code> is some weird extension available on GNU and who-knows-what-other Unixy systems (but <strong>NOT</strong> part of POSIX).</p>\n'}]
['https://Stackoverflow.com/questions/10680', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1084/']