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.

Était-ce utile?

La 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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top