简体   繁体   中英

Mac OS X equivalent for TerminateProcess(GetCurrentProcess,0);

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 .

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.

出口(0);


请记住,如果您调用exit()或TerminateProcess(),您将立即终止应用程序,即没有析构函数调用,您可能希望完成的清理工作(当然操作系统会清理它可以做的一切) 。

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