Cocoa in the Shell

Simulate a Kernel Panic on Mac OS X

Not so far ago I was lost on the net, —because you know, the net is vast and infinite—, and I found a piece of code to simulate a Kernel Panic in the osxbook site.

And well, as we are Mac users, we don’t see this kind of thing very often —not like on Wi…—, so I decided to share this little piece of code.

#include <sys/types.h>
#include <sys/sysctl.h>
define KERN_PANICINFO_TEST (KERN_PANICINFO_IMAGE + 2)

int main(void)
{
    size_t oldnewlen = 0;
    int mib[3] = { CTL_KERN, KERN_PANICINFO, KERN_PANICINFO_TEST };
    return sysctl(mib, 3, NULL, (void*)&oldnewlen, NULL, oldnewlen);
}

gcc panic_test.c -o panic_test
sudo ./panic_test

You have to be root to execute the program, because of sysctl().

There is another post on osxbook to show how you can change your panic screen, if you don’t know what to do…

Tags: ,