简体   繁体   中英

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

In C++11 or later, we can call std::quick_exit to exit a process without any unwinding, that is, no destructor will be called [after | during] std::quick_exit .

I have a project:

  1. It has a global object, and there is a fatal bug in the destructor of the global object;
  2. I have no access to the source of the global object;
  3. If I can call std::quick_exit at the last line of main function, the bug won't be triggered;
  4. For some reason, the project must be compiled with a C++98 compiler; that is to say, I cannot call std::quick_exit in a C++98 compiler.

In short:

What function in C++98 is equivalent to C++11's std::quick_exit ?

Under Windows, I can call ExitProcess(0) to forcibly exit a process without any cleanup.

What's the counterpart under Linux?

You can use abort() from <cstdlib> . It sends a SIGABRT to a process and if the signal is not caught the program is terminated without calling any destruction routines like atexit() or any destructors.

More info here: link

Edit: std::quick_exit exits normally, whereas calling abort() results in abnormal termination, don't know if that's a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM