How to exit a process without unwinding in C ++ 98?

In C ++ 11 or later, we can call std::quick_exitto exit the process without unwinding, i.e. the destructor will not be called [after | during] std::quick_exit.

I have a project:

  • It has a global object, and there is a fatal error in the global object's destructor;
  • I do not have access to the source of the global object;
  • If I can call std::quick_exitthe function in the last line main, the error will not be triggered;
  • For some reason, the project must be compiled using the C ++ 98 compiler; that is, I cannot call std::quick_exitin the C ++ 98 compiler.

In short:

Which function in C ++ 98 is equivalent to C ++ 11 std::quick_exit?

On Windows, I can call ExitProcess(0)to force exit the process without any cleanup.

What is under Linux?

+4
source share
1 answer

You can use abort()from <cstdlib>. It sends SIGABRTto the process, and if the signal is not caught, the program terminates without calling any destruction procedures, such as atexit()or any destructors.

Additional information here: link

Edit: std::quick_exitterminates normally, while the call abort()leads to abnormal termination, I do not know if this problem was.

+3
source

Source: https://habr.com/ru/post/1673380/


All Articles