7

Is there a "good" way to crash OS X? I need it for testing particularities.

It needs to be good enough not to cause permanent/ unrecoverable damage to the OS and hardware. I know I can just pull-plug (force shutdown via power button), but it seems dangerous to the hardware if done often.

I'm thinking possibly an app that has a ≪Crash OS≫ button? Anyone know of such a thing?

Pacerier
  • 3,189
  • 1
    “Crash” really - what about the shutdown command... issued in terminal with admin rights... – Solar Mike Feb 16 '18 at 07:40
  • 2
    What do you mean by crash? And what means „damage“? Any crash/kernel panic can lead to corrupted data for instance. – nohillside Feb 16 '18 at 08:28
  • 2
    As it‘s nearly impossible to reliably crash macOS from user space a self-developed kernel extension might be a way. Or just run shutdown or halt. – nohillside Feb 16 '18 at 08:30
  • @patrix, "damage" meaning hurting the hardware in such a way that I can't undo it. The gripe I have with "shutdown" is that it doesn't seem like a true and blue crash. I'm trying to test the behavior of a true "pullplug", but of course in a way as close as possible without hurting my hardware. There are windows apps that can be downloaded which actually crashes the OS when they run; I'm looking for such stuff for Mac. – Pacerier Feb 16 '18 at 08:37
  • 4
    I'm a little confused as to what you're trying to emulate here. Perhaps you could define crash more definitively? For example, do you want a kernel panic? Or, do you want the OS to freeze? Or, is it just that you want the Mac to power off (i.e. shutdown) or reboot suddenly in a non-graceful way? In your comment to @patrix you do mention there are Windows apps that do what you want, so perhaps you could list a couple to help clarify what you need? – Monomeeth Feb 16 '18 at 09:38
  • Just pull the power cable (assuming you have a Mini or iMac). The worst hardware damage is an unbootable boot drive... – nohillside Feb 16 '18 at 09:46
  • 1
    Do your testing with a Virtual Machine! – user3439894 Feb 16 '18 at 14:17
  • @patrix, Re "unbootable.."; that's a logical error which can eventually be fixed right? – Pacerier Feb 16 '18 at 15:59
  • @Monomeeth, basically testing how a selected app will behave upon unexpected crashes. Crash could be any random way of safely crashing the computer as long as it wouldn't do permanent hardware damage. – Pacerier Feb 16 '18 at 15:59

2 Answers2

9

I assume you mean kernel panic:

Kernel Panic, though sounding scary, is simply an occurrence when your Mac restarts for no obvious reason. Your Mac’s screen goes black giving you various warning messages like “You need to restart your computer.” Note that the presence of the warning message is what distinguishes Kernel Panic from usual Mac restarts and app crashes. In other words, Kernel Panic is just a Mac version of “blue screen of death” on Windows.

To start a kernel panic, you can issue the following command from Terminal:

sudo dtrace -w -n "BEGIN{ panic();}"

You will need to disable SIP if you have El Capitan or later. You can find instructions to do it here. It works for any version of macOS that has SIP, but you should NOT do it unless you really need to, since it is a security risk. If you do, you should re-enable it when your work is done.

Or an even better option is to test your software in a virtual machine using a virtualization software like Parallels or VMWare. This way, you won't damage your computer in any way.

This is not completely harmless if you try it on your actual machine instead of a VM. There is no completely harmless way of crashing your system. In my case, it didn't do any damage to my system, but you have been warned.

  • Is the harm limited to the logical filesystem ("And so it's fixable?") or does it harm the hardware itself? – Pacerier Feb 16 '18 at 15:59
  • Hardware will most likely not get harmed. –  Feb 16 '18 at 16:02
  • 2
    @Pacerier It's the equivalent of disconnecting the power/battery while the computer is running. Not going to harm your hardware, but data loss is a possibility. – Wowfunhappy Feb 17 '18 at 03:18
  • @Pacerier : the hardware and the filesystem can’t be damaged. But a synchronisation in progress through any kind of network can. An application using an internal DB (sqlite) or a simple state file (plist) can be damaged. NVRAM can get corrupted if you use nvram, pmset, or System Preferences at the same time. – dan Feb 17 '18 at 08:40
  • 1
    It's really not a security risk if you do this testing in a Virtual Machine that's being used just for this test and this sort of testing really should not be done to the physically install and is exactly what a VM is for, among many other things. – user3439894 Feb 19 '18 at 16:37
  • FYI a kernel panic is more than "an occurrence when your Mac restarts for no obvious reason", though it may appear there's nothing more to it. What's happening is the core of the OS (the "kernel") has encountered an unexpected condition which it is unsure how to properly handle without damage to hardware or further system instability. Normally the action the kernel decides to take in this situation is to reset and reboot, but in some cases other less drastic actions can be taken. – Josh Feb 22 '18 at 22:47
  • 1
    @danielAzuelos the filesystem can be damaged if writes are in progress which don't complete. Application data loss is also likely. Note that HFS+ and APFS have a "journal" which helps to repair the filesystem and greatly minimizes the chances of total filesystem data loss, but it still means the journal needs to be replayed. If you care about your data, make backups and try to always safely unmount disks (and a kernel panic is not a safe unmount) – Josh Feb 22 '18 at 22:53
  • @Wowfunhappy, Do you mean that if the battery gets fully drained or disconnected while the laptop is in use, the life of the hardware will not be affected? – Pacerier Mar 01 '18 at 23:41
  • @danielAzuelos, Re "NVRAM" etc; But those can be fixed with a reset right? Or do you mean the life of the hardware is affected? – Pacerier Mar 01 '18 at 23:43
  • @Pacerier Well, it’s not great for the battery, but other than that, yes. it might cause data loss but it won’t cause hardware damage. I can think of exceptions to this (maybe a cooling system that must shut down cleanly to prevent overhearing) but not your average laptop. – Wowfunhappy Mar 03 '18 at 02:55
-1

You could kill launchd - sudo killall launchd, which manages daemons, applications and scripts. This causes macOS to crash to a black screen because the parent of all running processes has been killed, so the OS cannot continue running normally