Any way to catch exit()?
Leo de Wit
leo at philmds.UUCP
Sun Aug 28 16:28:50 AEST 1988
In article <967 at cbnews.ATT.COM> lvc at cbnews.ATT.COM (Lawrence V. Cipriani) writes:
>One solution that I have employed is to define my own exit routine.
>When the program terminates my exit routine is called, and does what
>I want.
>
> void exit(e)
> int e;
> {
> ...whatever...
> _exit(e); /* still need this sucker */
> }
>
>This probably is non-portable but should solve your problem (if I
>understood it correctly).
One of the problems looming up is that exit() should flush stdio buffers.
(this should be part of ...whatever...). I don't know how that can be
done in a portable manner. Ultrix seems to use _cleanup() at this point.
There is a funny thing about _cleanup():
It is called without parameters. If I run the following program through adb:
main()
{
exit(0);
}
then _cleanup() does just: ret.
If I run the following however:
main()
{
printf("12345");
exit(0);
}
then _cleanup() does a lot of stuff. It seems that if stdio is not used
a simple version of _cleanup is used; if it IS used, a complicated one
is used that does a _filewalk() or something. Probably has something to
do with keeping binary sizes small, but I can't figure out how you can
have several _cleanup() 's in one library. Anyone knows?
Leo.
More information about the Comp.lang.c
mailing list