Close the application immediately

Is there a way to stop execution, something like SIG_ABRT, but right away, even if we're not on the main thread?


source to share

3 answers

Core Foundation has a macro HALT

that should do the trick, if you really, really think about it, you need 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)
        #error Compiler not supported
#if defined(__arm__)
    #define HALT do {asm __volatile__("bkpt 0xCF"); kill(getpid(), 9); } while (0)




If you are using a Macintosh application, " [[NSApp sharedApplication] terminate: self]

" will work.

On the iPhone, you can even do " exit(-1)

", but Apple will NOT accept any applications that suddenly or in any way terminate other than the user killing the application. Here is a related question with some helpful answers for you .



Assuming you don't like exit () or _exit (), which have some cleanup semantics, you can go with s

#include <signal.h>

kill( getpid(), SIGKILL );


And if you are on windows (assuming since "cocoa" is checked) you can use

TerminateProcess( GetCurrentProcess(), -1 );


This is all pretty tough, so you have to be pretty bad for it.



All Articles