Today i was Just looking through my book and than i just wanted to try something from the book and when i tried it my pc crashed...Now dont say my pc is crap
SPECS:
Proc: AMD phenom II 1.8 GHz Quad Core
Ram: 4 gig
hardrives : one 500 gb and one 320 gb
graphics card: nvidia gt 430
and i have 5 fans cooling it with blue leds
Here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main()
{
// WRONG: u can never be less than 0; the condition will always succeed
//THIS WILL CRASH!!!!!!
for (unsigned u = 10; u >= 0; --u)
std::cout << u << std::endl;
return 0;
}
Cooling wouldn't really be the issue, you probably have bad memory that you don't normally use til this program expended all of it. Only people that jump to the conclusion a computer is shitty because something didn't work are those uneducated with the ways of the force hardware. So many things can go wrong with the manufacturing of hardware, something as small as a hair can cause a circuit to malfunction. It's not uncommon to get brand spanking new defective hardware.
cout is essentially a system call though, what the kernel does with the output and how much of it it stores is implementation defined if I had to guess.
std::cout << "'bout to crash your sh*t";
long crasher[10000000000][10000000000];
Or even better:
1 2 3 4 5 6 7 8
std::cout << "'bout to crash your sh*t";
for(int t = 0; t < t + 1; t++)
{
long crasher[10000000000][10000000000];
}
// Just incase this dude gots a super pc
Disch's example is an infinite loop that keeps spawning an exact copy of itself, each copy creates more copies of itself in an infinite loop until you run out of memory.
http://en.wikipedia.org/wiki/Fork_bomb
Chrisname's example takes random data from the kernel RNG and writes it directly to memory, effectively overwriting programs in memory and corrupting the system.
Fredbill, those just release exceptions and create nothing. You can't allocate that much memory- it just creates an exception when you do and sets the array to 0.
Yes. But depending on the OS, it might not hang the system.
Linux will either kill the process, or the process will simply silently fail to allocate memory and continue in the loop while nothing happens to the rest of the system, or the OOM in the kernel may start killing random things. This all depends on how that system's kernel is configured.
The last time I tried it on Windows, the kernel will just kill it when it uses too much memory. I don't know if there is a way to change this, I've never bothered to look.
Last time I tried that on a Mac, OS X simply continued to expand the swap file until the entire system was unusable. I don't know if this can be configured, or has changed in recent version of OS X.