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 4 of 6 Topic 4068 of 4400
Post > Topic >>

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

by Hal Vaughan <hal@[EMAIL PROTECTED] > Mar 13, 2008 at 11:26 PM

Jeff Schwab wrote:

> 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

That's one of the little glitches in dealing with a new language:
different
terms.  The searches I did had "on exit" and "onexit" and it never
occurred
to me to look at "atexit()."

I keep hearing and reading references to Boost but haven't looked at it
yet,
but it looks like I'm going to have to read up and learn about it no
matter
what.

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

It's on Linux and I seriously doubt this will be used on another OS, but
it
is possible.  I can always leave that issue up to the masochist that wants
to ****t the code over.

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

That gives me several options to put in so most cases should be covered.

Thanks!

Hal
 




 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 12:54:52 PST 2009.