Talk About Network

Google





Programming > C - C++ Learning > Re: Any Kind of...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 6 Topic 4068 of 4400
Post > Topic >>

Re: Any Kind of do_on_exit() in C or C++?

by Jeff Schwab <jeff@[EMAIL PROTECTED] > Mar 13, 2008 at 03:27 PM

Hal Vaughan wrote:
> In Java actions can be set to perform on exit.  Is there any way to do
that
> in C or C++?

As Ian said, check out std::atexit.  See also std::terminate.  Beyond 
those, the Boost.Test Program Execution Monitor may be your most 
****table option.

http://www.boost.org/libs/test/doc/components/prg_exec_monitor/index.html


> Is there any way to catch a kill signal and if one is sent,
> do some closing down routines before dying?

It's usually not too difficult, but is inherently somewhat non-****table. 
  If Boost.Test doesn't do what you need, and you're on a POSIX system, 
try installing handlers for SIGSEGV and whatever other signals interest 
you using the POSIX sigaction function.

> I need to be able to shut down the connection to hardware when the
program
> ends and most of the time that isn't an issue (since I have an exit
> command), but it would help if there were a way to do that if the
program
> were killed accidently as well.  (And I'm sure there's no way to do that
in
> case of a crash or core dump!)

Again, if Boost.Test doesn't cover your situation, but if you are using 
the GNU C library, man catchsegv(1).  In the worst case scenario, you 
might arrange for your stack trace to include whatever info some other 
process needs to close the hardware gracefully.

http://www.fifi.org/cgi-bin/man2html/usr/share/man/man1/catchsegv.1.gz
 




 6 Posts in Topic:
Any Kind of do_on_exit() in C or C++?
Hal Vaughan <hal@[EMAI  2008-03-13 21:56:57 
Re: Any Kind of do_on_exit() in C or C++?
Ian Collins <ian-news@  2008-03-14 11:09:02 
Re: Any Kind of do_on_exit() in C or C++?
Jeff Schwab <jeff@[EMA  2008-03-13 15:27:00 
Re: Any Kind of do_on_exit() in C or C++?
Hal Vaughan <hal@[EMAI  2008-03-13 23:26:35 
Re: Any Kind of do_on_exit() in C or C++?
Jeff Schwab <jeff@[EMA  2008-03-13 19:08:49 
Re: Any Kind of do_on_exit() in C or C++?
Micah Cowan <micah@[EM  2008-03-14 09:51:59 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 11:46:47 PST 2009.