Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!pasteur!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!hp4nl!philmds!leo From: leo@philmds.UUCP (Leo de Wit) Newsgroups: comp.lang.c Subject: Re: Any way to catch exit()? Keywords: _cleanup Message-ID: <771@philmds.UUCP> Date: 28 Aug 88 06:28:50 GMT References: <8808261432.AA11635@ucbvax.Berkeley.EDU> <967@cbnews.ATT.COM> Reply-To: leo@philmds.UUCP (Leo de Wit) Organization: Philips I&E DTS Eindhoven Lines: 43 In article <967@cbnews.ATT.COM> lvc@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.