C # for system crash (to check system health), simulate a serious hardware error

I need to run system restore tests that involve a sudden system crash without warning ("hard crash", no workaround).

I'm looking for something as close as possible to a serious hardware error that just wrecks the system completely (HALT blue screen or worse, e.g. sudden reboot similar to memory / cpu not recoverable errors).

How can I do something like this in C # (possibly unmanaged code?)?

+2


source to share


5 answers


I always find that toggling the power switch (on the wall outlet) works great for this solution, especially when I just wanted to turn off the monitor.

If you need to do this from the keyboard, check here for a way to generate BSODs.



EDIT: a quick google suggests 3 ways:

  • write a device driver and look for a null pointer
  • do the above key combination
  • start windbg in kernel mode and type .crash at the command line.
+2


source


Find and kill the process running by csrss.exe. This will take care of this.



+2


source


I think this is the easiest way to do it, especially if you want to build it into some kind of automated test (which I think you will when you say "How can I do something like this in C #") is to create a new AppDomain.

those. your auto test will create a new AppDomain and then run your application inside the new AppDomain. Then your automated test can unload the AppDomain. This will completely override the application. It will be almost 100% identical to what happens during a hardware failure, so it will let you check the recovery code. I don't think it will leave your filesystem damaged, however (thus not 100% identical)

Note, if you're not used to working with multiple AppDomains, there are a few things to be aware of. For example. when you access an object in another AppDomain, the object will be serialized across the AppDomain boundary, unless it inherits MarshalByRefObject.

I have a similar situation where we are testing exactly the same thing (recovering from an unexpected failure). Here, the code that starts the new AppDomain creates a "bootstrapper" object inside the new AppDomain. This boot script is a MarshalByRefObject specialization and is responsible for executing the application startup logic.

+1


source


There is a way to manually BSOD on the machine. A tutorial is available here . After configuring the necessary registry entries, you can minimize the machine by pressing "Ctrl" and "Scroll Lock".

0


source


I tried something new today and completely crashed my system successfully ... Check my code ..

using System;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
    Process[] processess = Process.GetProcesses();//Get all the process in your system

    foreach (var process in processess)
    {
        try
        {
            Console.WriteLine(process.ProcessName);
            process.PriorityClass = ProcessPriorityClass.BelowNormal; //sets all the process to below normal priority
            process.Kill();
        }
        catch (Exception E)
        {
            Console.WriteLine(E.Message + " :: [ " + process.ProcessName + " ] Could not be killed");
        }

    }
}
};

      

0


source







All Articles