I am looking for a simple and uncatchable way to terminate the Mac port of my C++ application. In Windows I was using
TerminateProcess(GetCurrentProcess, 0);
What's the equivalent command I can use with Mac OS X / XCode / GCC?
I am looking for a simple and uncatchable way to terminate the Mac port of my C++ application. In Windows I was using
TerminateProcess(GetCurrentProcess, 0);
What's the equivalent command I can use with Mac OS X / XCode / GCC?
Actually you want _exit
if you want to have the same semantics as TerminateProcess
. exit
semantics are more closely aligned with ExitProcess
.
Keep in mind that if either you call exit() or TerminateProcess(), you'll get you application terminated immediately, i.e. no destructor calls, no cleanup you may expect to be done is done (of course OS cleans up everything it can).
A closer to ProcessTerminate will be to send a SIGKILL with kill, both terminate the current process immediately and can't be trapped. This is the same as _exit
kill(getpid(), SIGKILL);
Actually, both exit() and _exit() involve the CRT, which means various actions are still taken. (Not sure about atexit, I haven't checked)
TerminateProcess on Windows is on the OS level, so it sidesteps all of the CRT. If you want to do the same thing on the Mac, your best bet is getting your hands dirty with mach functions. In this case:
#include <mach/mach.h>
... // lots of your code here
task_terminate(mach_task_self());
That's about as uncatchable as you can get.