# on_exit(...) function



## jsika (Jan 13, 2020)

Could somebody tell me how to replace a missing function *on_exit*? It's a little bit non-standard, available under Linux, but very useful. I need to pass _args_ that _atexit_ cannot.


----------



## _martin (Jan 17, 2020)

I don't know if this is possible. As a suggestion maybe to use atexit() with the combination of global variable that will serve the purpose of the argument.


----------



## SirDice (Jan 17, 2020)

> This function comes from SunOS 4, but is also present in glibc.  It
> no longer occurs in Solaris (SunOS 5).  *Portable application should
> avoid this function, and use the standard atexit(3) instead.*


From the on_exit(3) man page.


----------



## _martin (Jan 17, 2020)

SirDice Well, if he's porting the SW it might be that he needs to find a workaround. Not using it may not be an option (depends).


----------



## SirDice (Jan 17, 2020)

True. But that isn't really clear from the original question. It might be an application jsika wrote himself.


----------



## jsika (Jan 24, 2020)

As _martin said, I resolved it with atexit() and a global value. It was for a web server, to detect termination of fork/eval process.
I've even found __cxa_atexit function from sources, which is similar, but it didn't work for me at all.


----------



## memreflect (Jan 24, 2020)

jsika said:


> As _martin said, I resolved it with atexit() and a global value. It was for a web server, to detect termination of fork/eval process.
> I've even found __cxa_atexit function from sources, which is similar, but it didn't work for me at all.


Glad you got things working.  

Just so you and future readers are aware, `__cxa_atexit` isn't meant to be called directly by application-level code.  See https://wiki.openoffice.org/wiki/GCC_cxa_atexit and GCC - C++ Dialect Options: `-fuse-cxa-atexit` for more GCC-specific information; the clang implementation is presumably compatible, but I cannot guarantee that with a reasonable amount of certainty.  Things may differ in the case of GCC compiled for the ARM EABI (GCC Internals: Target Hook `bool TARGET_CXX_USE_AEABI_ATEXIT (void)`).

Edit: The OSDev wiki has a bit of info on it as well, so it's highly likely to be some low-level stuff for compiler implementations rather than something you'd call yourself in an application.


----------

