Question

For functions registered using atexit(): Is it possible to retrieve references to them, to call them directly?

Although this is meant as a general question, solutions regarding the use of gcc/glibc are welcome.

Was it helpful?

Solution

Not in any portable way, no. The list of registered functions is owned by the runtime library, and there is no interface to access it.

For glibc specifics as per your comment, the exit handlers are implemented by exit.c and exit.h. I haven't studied them intensely enough to figure out of it's possible to drill through the abstraction/data hiding. You might need to e.g. include glibc-specific headers that probably aren't generally available, for instance.

OTHER TIPS

No. However, if you have control over all the code in the application, you could maintain a list yourself, and register a single function to the real atexit() which would run through the list when the system is terminated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top