Sithee, I tried out this version of what you're doing :code:
void breakme()
{
void* foo;
foo=malloc(10000000);
breakme();
}main()
{
breakme();
}
And here's the result of the run :
code:
jon@hadron:~> a.out
Killed
jon@hadron:~>
It took about 2 minutes before it exhausted the memory. During that time I could still log in and execute commands. I have no idea what would happen in Windows, since I don't have a C compiler
Does someone want to try it and post what happens? I'm guessing that the same thing will happen - the prog will run for a while, and then die when it exhausts the memory.
I suppose an explanation of how my proggie works is in order. fork() is a system call that creates a new process that is an exact duplicate of the one that called fork() - all global and local vars, filehandles, sockets, etc. are duplicated. Both the old and new process continue execution at the statement immediately following the fork; the function returns 0 to the child process and the kid's PID to the parent process.
If you use Java, it's a bit like creating a new thread, except that the new process gets it's own memory space. Usually you use it like this :
code:
if (pid = fork())
{
// we're the parent process, do something
// while we wait for the child to exit.
}
else
{
// we're the child process, do something
// and exit.
}
in my case, though, the program just repeatedly calls fork() - and each of its children does the same thing. So each iteration of the loop spawns 2^(n+1) new processes, which means that by the 15th iteration you've completely filled up the Unix process table & no new processes can be started - at which point the kernel flips out completely
If you haven't used fork() in a proggie yet, I *highly* recommend you try it. It makes writing certain programs, like servers, *VERY* easy. Just beware of looping yourself into process hell.