Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutdown Hook c++

is there some way to run code on termination, no matter what kind termination (abnormal,normal,uncaught exception etc.)? I know its actually possible in Java, but is it even possible in C++? Im assuming a windows environment.

like image 279
Sebastian Hoffmann Avatar asked Aug 07 '11 18:08

Sebastian Hoffmann


2 Answers

No -- if somebody invokes TerminateProcess, your process will be destroyed without further adieu, and (in particular) without any chance to run any more code in the process of shutting down.

like image 164
Jerry Coffin Avatar answered Oct 30 '22 09:10

Jerry Coffin


For normal closing applciation I would suggest

atexit()
like image 45
Drake Avatar answered Oct 30 '22 09:10

Drake