How can I provoke Windows to hang (freeze)?

179

59

I need to test equipment behaviour in the event that Windows hard hangs/freezes (e.g. frozen screen, no LEDs blinking, no reaction to inputs, including Ctrl+Alt+Del, etc.). In order to have enough experiments in a reasonably short time I need to initiate these hangs either programmatically or otherwise.

I am interested in Windows 10 in particular but any working way for other versions is appreciated.

Every search I've done on this topic not surprisingly brings me to discussions on how to eliminate these situations, not provoke them. So the question may seem odd enough.

Feedback: I've tried many of the recipes offered in answers and comments. First of all, I was not interested in crashes that bring BSoD (that's why I described a freeze, not a crash).

I must confess that Windows 10 64-bit showed good resistance to many of the ways. It copes with almost any CPU-load method (including fork-bomb, loops, etc.) quite well. Methods that raise immediate errors (most of NotMyFault hang methods) are handled by the OS with reboot or shutdown (which is not what I pursued). The best results were achieved by memory leak methods of NotMyFault — real freeze with no chance of reboot.

Finally, I was impressed by amount of documentation by Microsoft that talks about making Windows freeze. Looks like they know this part much better than the opposite (fighting freezes) ;-)

hypers

Posted 2017-11-02T08:03:23.693

Reputation: 1 533

Comments are not for extended discussion; this conversation has been moved to chat.

– DavidPostill – 2017-11-04T16:38:35.623

3There is a calculation you could do using calculator, which freezes the core on the CPU until it's completed it. On a quad core machine you'd do it four times obviously. But I can't for the life of me remember the maths equation that causes it. – mickburkejnr – 2017-11-06T16:15:25.403

6@mickburkejnr It's factorial of 100000. Switch to "Scientific View" type 100000 and press "n!". This worked well on old Windows versions. Nowadays you'll get a warning that this calculation may take a long time and you can cancel it. – duenni – 2017-11-07T07:08:19.590

@duenni Mine will refuse to calculate it and yells 'overflow' instead. – None – 2017-11-07T14:01:54.560

@mickburkejnr I did this lots of times with WinXP calc, and it never froze my system. If you machine froze because of it, the CPU must have been overheating and shutting down to prevent thermal damage. – Ruslan – 2017-11-07T15:03:01.173

26Just start using it. – samazi – 2017-11-08T05:57:50.453

I would totally need an answer to the opposite question. – IllidanS4 wants Monica back – 2017-11-08T15:57:12.513

The most common way I've had my computer freeze on me was to write a python script that (accidentally) uses unbounded memory. Running such a script from IDLE has never failed to freeze my computer. – Justin – 2017-11-08T19:57:20.503

6Installing upgrades always worked for me. – Daniel R Hicks – 2017-11-10T03:29:31.387

Answers

229

Maybe this can help: Forcing a System Crash from the Keyboard

With USB keyboards, you must enable the keyboard-initiated crash in the registry. In the registry key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\kbdhid\Parameters, create a value named CrashOnCtrlScroll, and set it equal to a REG_DWORD value of 0x01.

You must restart the system for these settings to take effect.

After this is completed, the keyboard crash can be initiated by using the following hotkey sequence: Hold down the rightmost CTRL key, and press the SCROLL LOCK key twice.

Or you could start a fork bomb: see this SO question

There is also NotMyFault

Notmyfault is a tool that you can use to crash, hang, and cause kernel memory leaks on your Windows system. It’s useful for learning how to identify and diagnose device driver and hardware problems, and you can also use it to generate blue screen dump files on misbehaving systems.

duenni

Posted 2017-11-02T08:03:23.693

Reputation: 2 109

9Tried ForkBomb and NotMyFault. One of the leak methods seems to do what I want. Others are not useful as they bring to reboot/shutdown not freeze. Thanks a lot. – hypers – 2017-11-03T09:34:46.343

6CtrlScroll brings you a BSOD. Whether that freezes the system for debugging or just reboots it, depends on boot settings. – user1686 – 2017-11-04T13:51:58.223

51Aaannnddd duenni is never allowed near my computers. Ever. – corsiKa – 2017-11-06T23:14:14.343

24

It sounds like you're testing the reaction of an external device to an OS becoming unresponsive.

If your hardware can be connected to a virtualized Windows install, then you can pause and resume the virtual machine as many times as you like. Install the desired OS in a VirtualBox (or other desktop virtualization) environment, expose whatever hardware interface is being used (USB, Ethernet, or whatever) to the VM.

You can then pause and resume the virtual machine at will.

barbecue

Posted 2017-11-02T08:03:23.693

Reputation: 1 065

23

At least under an older Windows version (some years ago) the following worked:

I wrote a C program with an endless loop:

while(1) {}

... then I gave that program "realtime priority" in the task manager (there is also an API which can do this).

On a multi-core system I would need to do this multiple times so one loop is running on each core...

Martin Rosenau

Posted 2017-11-02T08:03:23.693

Reputation: 562

39To heat your CPU less while doing that: put _mm_pause() from #include <immintrin.h> in the loop. That's a CPU hardware instruction, not a "sleep" system call of any sort; as far as the OS is concerned, your process is indistinguishable from SuperPI; the difference is just in how much power the CPU consumes while running the loop. – Peter Cordes – 2017-11-02T12:06:36.147

5I'm not sure if that stops the kernel mode parts of windows from working. – CodesInChaos – 2017-11-02T15:49:19.150

2@CodesInChaos: Most of the kernel threads run at normal priority. One of these per CPU and the kernel is pretty much done too. – Joshua – 2017-11-02T18:47:36.570

Another technique involving x86 assembly (STI + HLT): https://stackoverflow.com/questions/3747847/how-to-completely-suspend-the-processor

– meklarian – 2017-11-02T22:29:13.583

You may have better results by also setting the affinity of each instance of the process to a particular core. – None – 2017-11-03T18:10:51.137

3@meklarian: Should be CLI; HLT. Presumably you have to do it from privileged mode, though. In principle it can still be rescued by NMI or similar. – Nate Eldredge – 2017-11-04T15:04:32.797

@NateEldredge If it works then CLI followed by an endless loop will also do the job. There seem to be CPUs (I know from virtual machines!) which will treat HLT as invalid instruction when interrupts are disabled. The result would simply be an "invalid opcode" exception. – Martin Rosenau – 2017-11-04T15:25:32.287

@MartinRosenau do such CPUs really invoke #UD in such condition? I only saw Bochs panic on this, but not invoke the #UD handler. – Ruslan – 2017-11-07T15:09:13.967

You need to get a bit more specific than "an older version". Note that NT-based Windows (including 2000, XP, and all their successors) is a new 32/64 bit OS. Before that, Windows was just a 16-bit task/window manager running on top of DOS. – Isaac Rabinovitch – 2017-11-07T23:02:16.560

@IsaacRabinovitch Writing "an older version" I'm saying that I'm not sure about Windows 10 64-bit. I'm not sure any more if I observed that behaviour on Windows 2000, 32-bit or under Windows XP, 32-bit. But I'm sure it was one of these two versions. – Martin Rosenau – 2017-11-08T05:12:41.940

10

The strongest kernel hang (i.e., no mouse tracking, etc.) is when code goes into an infinite loop in kernel mode with interrupts off.

It's possible to achieve this with a device driver, and even better, you can write the driver so that it starts and stops the hang under your control (assuming the infinite loop is testing the condition you're in control of).

How to write and install this driver would be the topic of another question or three, but that's the approach I'd take.

Dylan McNamee

Posted 2017-11-02T08:03:23.693

Reputation: 332

8

Please check the following question on StackOverflow which is similar to yours: How to make windows freeze for short period of time

The tl;dr of it is that there's no way to (reliably) do it.

Rather than freezing or getting Windows to hang, maybe you can just interrupt the communication with your equipment.

I have no idea what your equipment is and how you connect it. If it's USB or Ethernet adapter, e.g, you could easily deactivate it in the Device Manager or unplug? If you forcefully crash or hang the system you might damage your system in various ways, so be careful with what you do.

Ralf

Posted 2017-11-02T08:03:23.693

Reputation: 269

1I will consider physical disconnect of the equipment if I'm not satisfied with software results. Thanks. – hypers – 2017-11-03T09:36:49.443

5

Is kernel debug mode not an option?

I've set it up in Windows 7, and the linked instructions in this answer specify XP or later, so it should work with Windows 10.

I've set it up over FireWire/1394, since it's the easiest, in my opinion. But you can also do it over the network or USB (and more).

Basically,

Setup the target computer by running these commands in an elevated prompt (picking a channel n):

bcdedit /debug on
bcdedit /dbgsettings 1394 channel:n

Which is the same as going to the boot tab of msconfig, and selecting the 'Advanced' button:

enter image description here

enter image description here

Then (after rebooting the target computer), run WinDbg on the host computer using the same bitness of WinDbg of the target computer.

Then it's just a matter of pausing kernel execution whenever you want from the host computer. If you test equipment has some asynchronous operation that it is running this should be as effective as other means.

Nick

Posted 2017-11-02T08:03:23.693

Reputation: 568

Interesting way. Needs a second PC though. But will try when possible. – hypers – 2017-11-09T17:35:33.867

2

I don't know if this qualifies as a total freeze because the mouse cursor still moves on the screen, but Windows 7 UI becomes unresponsive if you have device I/O errors more specifically a hard drive failure. One of my hard drives was self-reporting imminent drive failure via SMART and Windows 7 would mount it but hang whenever I tried to access certain files saved on it. The UI would lock up (except for the mouse cursor movement) for up to 5 minutes until it either could read the file or dismounted the drive after the time-out. I don't know if Windows uses the system clock for the timeout, but maybe if you somehow freeze the time you can extend the timeout length? Maybe this will get you part way there, but not 100% the answer you're looking for.

Dotes

Posted 2017-11-02T08:03:23.693

Reputation: 121

2

This bug freezes Windows pretty quickly due to resource exhausting. Easy to reproduce too.

As it turns out, this is actually a bug in how the command line (more specifically cmd.exe) parses batch files and could lead to a quick denial of service type attack; putting the following line in a batch file (with no new lines) will consume massive amounts of memory very quickly due to this bug (as an example):

^ nul<^

Long story short, when a caret is at the end of the file, the actual end of file is 'ignored' and the file handle 'reset' to 0 (essentially) so that the batch is parsed again (ad infinitum).

beatcracker

Posted 2017-11-02T08:03:23.693

Reputation: 2 334

2

Here's the source code of an application that I use in my debugging lessons. It shows how a user mode application can perform a sort of DoS attack.

You'll notice that your mouse cursor moves very seldom (once every eleven seconds on my machine). Potentially your PC will still react on the Power button if you wait long enough.

It works using an endless loop and setting the highest priority to the process (0x100 "realtime") and setting the highest priority to the threads (15 "time critical"). It will start 8 of them, which is enough for i7 computers. If you need more, adapt the loop. More of them will potentially slow down things more.

#include "stdafx.h"
#include <windows.h>
#include <string>
#include <sstream>
#include <iostream>

void WasteTime()
{
    int priority = 15;
    ::SetThreadPriority(::GetCurrentThread(), priority);
    while (true)
    {
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    ::SetPriorityClass(::GetCurrentProcess(), 0x100);
    for(int i=0; i<7; i++)
    {
        LPDWORD threadid = 0;
        ::CreateThread(NULL, 64*1024, (LPTHREAD_START_ROUTINE)&WasteTime, NULL, 0, threadid);
        ::Sleep(2000);
    }

    WasteTime();

    return 0;
}

Thomas Weller

Posted 2017-11-02T08:03:23.693

Reputation: 4 102

Beware that this program has undefined behavior in C++, so under certain optimization settings the compiler could replace the whole thing with ExitProcess(0) – Ben Voigt – 2017-11-10T19:27:21.337

@BenVoigt In that case (i.e. with g++) if -O0 were not enough, maybe gcc -Q -O0 --help=optimizers | grep enabled (and disabling the survived optimization by hands) may be solve the ExitProcess(0) issue? – Hastur – 2017-11-11T13:42:51.050

@BenVoigt: could you elaborate, which part do you consider as undefined behavior? – Thomas Weller – 2017-11-11T19:18:28.230

@BenVoigt IMHO the compiler can only optimize the return 0 statement, because that exists after the while(true). The compiler could find out that this is an unreachable statement. – Thomas Weller – 2017-11-11T19:29:50.420

The C++ language demands that every thread eventually makes progress, defined in terms of several types of observable behavior. Because the infinite loop never makes observable progress, the compiler can deduce that it is not reached, and remove not only it, but all code above it back to the closest branch. – Ben Voigt – 2017-11-12T06:18:00.930

See https://stackoverflow.com/a/30988141/103167

– Ben Voigt – 2017-11-12T06:19:42.307

@BenVoigt: Thanks for the reference. "By writing a loop, the programmer is asserting..." - yes. I'm asserting that the visible effect is heat. In the early days the saying was that a computer only does what the programmer told him to do. This is obviously gone with C++. Someone should delete C++ from the list of imperative programming languages in Wikipedia. I personally should totally drop C++ and find a new language. If I write an endless loop, I want it to be compiled as such. – Thomas Weller – 2017-11-12T11:40:08.693

If you want no optimization whatsoever, you indeed should move away from C++. The Standard has a list of visible effects ("observable behavior") that a compiler must preserve, but heat and time are not among them (synchronization operations are, which ultimately do give you control over timing) Please note that C does allow infinite loops, but there are a whole host of other circumstances in which it allows optimization potentially contrary to the intent of the programmer, so you'd better not use it either. – Ben Voigt – 2017-11-12T16:35:38.690

And finally you'd better not use any modern desktop-class processor, because all of them have non-deterministic timing and will do things you didn't ask for explicitly (eliding memory accesses using caching, speculative calculation, overlapping and reordering operations) – Ben Voigt – 2017-11-12T16:37:15.117

Finally, regarding "visible effect is heat": https://xkcd.com/1172/

– Ben Voigt – 2017-11-12T16:38:20.317

0

Did you try the CPUEater utility that is bundled with Process Lasso ? Ps. I do not work for bitsum.

beppe9000

Posted 2017-11-02T08:03:23.693

Reputation: 403

I think you mean "Have you tried", not "Did you try". :) – fabspro – 2017-11-12T22:12:56.783

@fabspro I think "Did you try" is correct because the OP already accepted another answer so the event I am referring to ("solving the problem") is in the past, but one could probably say internet is always happening. Anyways, if you suggest an edit I will gladly delegate the task of accepting it to the review queue. Source: https://www.englishforums.com/English/HaveYouTriedOrDidYouTry/zclxb/post.htm

– beppe9000 – 2017-11-12T23:18:37.040

I guess if he had solved the problem, your enquiry could have been a comment on his answer then - something like "when you were researching your problem, was one of the things you tried _______ utility?" perhaps... just suggesting things :) – fabspro – 2017-11-13T11:06:19.127

... touché :) – beppe9000 – 2017-11-14T01:55:59.170

huehuehuehuehue – fabspro – 2017-11-14T11:10:30.263

-2

If you really want to hang your PC, totally causing it to just freeze, simply use up all of its RAM and force it to page memory. That will go beyond mere freezing and really just overload the thing such that you can't even use Task Manager, not even by keyboard. Even when the process is terminated, it will take a long time for the PC to recover. (It's the best!)

You could for instance create a class with a pointer to itself, and in a while loop, create a new instance of that class forever, storing each new instance in the previous instance's pointer. Maybe add some doubles or vectors to the class too, to consume memory more quickly. Then you could have a timer that exits the while loop and deconstructs everything; of course, you'll have to wait a bit for it to recover.

Andrew

Posted 2017-11-02T08:03:23.693

Reputation: 175

-4

I would suggest simply creating a batch file with the following code:

@echo off
:x
start cmd.exe
start explorer.exe
start calc.exe
start notepad.exe
start iexplorer.exe
start paint.exe
goto x

This is probably the easiest and safest way to do it. You can replace the process names with any windows applications.

SLimy

Posted 2017-11-02T08:03:23.693

Reputation: 9

3This'll most likely just exhaust the RAM and cause the hard drive to be thrashed. Depending on your computer specs, it is possible that the computer will continue to work through this, especially since 4 of those programs listed are quite lightweight (iexplore.exe and maybe explorer.exe would have a bigger impact). It'll just kill off memory hogging processes automatically. – MoonRunestar – 2017-11-06T10:05:18.477

-10

  1. Go to C:\Windows\Temp\
  2. Hit Ctrl-a for Select All
  3. Hit Enter

asrhargar

Posted 2017-11-02T08:03:23.693

Reputation: 1

8You'd need many thousands of items for this to be vaguely effective! My %TEMP% folder is empty... – AlainD – 2017-11-03T15:22:24.897

6While this appears to be a legitimate attempt to answer the question, it's entirely unclear how exactly this is supposed to result in Windows locking up as requested by the OP. Please [edit] your question to explain why this will do what the OP wants. – I say Reinstate Monica – 2017-11-03T17:25:58.637

9I would feel sorry for anyone who have tried this and didn't realise that they've been hit by drive-by downloads with malicious software in there. – MoonRunestar – 2017-11-06T10:02:27.083