Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Halt app execution immediately

Is there a way to halt execution, somewhat like SIG_ABRT, but immediately, even if we're not on the main thread?

like image 820
andyvn22 Avatar asked May 20 '26 11:05

andyvn22


2 Answers

Core Foundation has a macro HALT that should do the trick, if you really, really think it's necessary to do this:

#if defined(__ppc__)
    #define HALT do {asm __volatile__("trap"); kill(getpid(), 9); } while (0)
#elif defined(__i386__) || defined(__x86_64__)
    #if defined(__GNUC__)
        #define HALT do {asm __volatile__("int3"); kill(getpid(), 9); } while (0)
    #elif defined(_MSC_VER)
        #define HALT do { DebugBreak(); abort(); } while (0)
    #else
        #error Compiler not supported
    #endif
#endif
#if defined(__arm__)
    #define HALT do {asm __volatile__("bkpt 0xCF"); kill(getpid(), 9); } while (0)
#endif
like image 162
jscs Avatar answered May 22 '26 00:05

jscs


If you're using a Macintosh app, "[[NSApp sharedApplication] terminate: self]" will work.

On an iPhone, you can even do "exit(-1)", but Apple will NOT accept any apps that abruptly or in any way terminate other than the user killing the app themselves. Here is a related question with some useful answers for you.

like image 20
Michael Dautermann Avatar answered May 22 '26 01:05

Michael Dautermann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!