How to determine safe mode in OSX

I have code that I want to run only if the user has not booted in safe mode. Is there any way I can use the standard CoreFoundation or C standard APIs that I can detect?

EDIT: here is my code thanks to my accepted answer:

#include <sys/sysctl.h> ... int safeBoot; int mib_name[2] = { CTL_KERN, KERN_SAFEBOOT }; size_t length = sizeof(safeBoot); if (!sysctl(mib_name, 2, &safeBoot, &length, NULL, 0)) { if (safeBoot == 1) { // We are in safe mode } else { // Normal mode. Continue… } } else { // Couldn't find safe boot information } 
+7
c macos
source share
1 answer

You can use sysctl as follows:

 sysctl -n kern.safeboot 

It gives 1 in safe boot mode and 0 in normal mode.

+6
source share

All Articles