美文网首页
OOM killer

OOM killer

作者: 帆子_8c3a | 来源:发表于2019-09-26 14:23 被阅读0次

下面程序触发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;
}

相关文章

网友评论

      本文标题:OOM killer

      本文链接:https://www.haomeiwen.com/subject/vgwoectx.html