下面程序触发OOM killer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define M (1024 * 1024)
#define K 1024
int main(int argc, char *argv[])
{
char *p;
int size =0;
while(1) {
p = (char *)malloc(K);
if (p == NULL){
printf("memory allocate failed!\n");
return -1;
}
memset(p, 0, K);
size += K;
if (size%(100*M) == 0){
printf("%d00M memory allocated\n", size/(100*M));
sleep(1);
}
}
return 0;
}
网友评论