8GB of RAM, the following code makes my system freeze. (not checked completely).
PHP Code:
/*
* test.c
*
* Copyright 2007 Vyacheslav Goltser <slavikg@gmail>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <signal.h>
#define SIZE 1024*1024*1024
void handler(int n) {
printf("I got a SIGINT\n");
_exit(0);
}
int main(int argc, char** argv)
{
long long int i = 1024*1024*1024;
printf("Asking for %d eight times\n", SIZE);
char *stuff1 = (char *)malloc(sizeof(char)*SIZE);
char *stuff2 = (char *)malloc(sizeof(char)*SIZE);
char *stuff3 = (char *)malloc(sizeof(char)*SIZE);
char *stuff4 = (char *)malloc(sizeof(char)*SIZE);
char *stuff5 = (char *)malloc(sizeof(char)*SIZE);
char *stuff6 = (char *)malloc(sizeof(char)*SIZE);
char *stuff7 = (char *)malloc(sizeof(char)*SIZE);
char *stuff8 = (char *)malloc(sizeof(char)*SIZE);
signal(SIGINT,handler);
while (i--) {
*(stuff1+i)=0;
*(stuff2+i)=0;
*(stuff3+i)=0;
*(stuff4+i)=0;
*(stuff5+i)=0;
*(stuff6+i)=0;
*(stuff7+i)=0;
*(stuff8+i)=0;
}
while (1) sleep(1);
return 0;
}
Bookmarks