zoukankan      html  css  js  c++  java
  • 不是一个缺页中断的例子,是栈撑爆的例子【原创】

     经高人也是我的好朋友的指点后,发现此文并不是缺页中断的例子,用户空间这样写实际上是栈溢出的例子,一个页为4k,一个栈为8M,栈撑爆了就会segment fault

    缺页中断在用户空间产生的话,只需要fork进程即可,创建新的进程就会产生缺页中断,因为会建立新的页表。

    test1.c

    #include <stdio.h>
    #include <stdlib.h>
    
    #define UNUSED_PARAMETER(x)  ((void)(x))
    
    int main(int argc, char *argv)
    {
        int i, j;
        char buf[4096][4096];
        
        UNUSED_PARAMETER(argc);
        UNUSED_PARAMETER(argv);
        
        for (i=0; i<4096; i++)
            for (j=0; j<4096; j++)
                buf[j][i] = 1;
            
        return 0;
    }

    test2.c

    #include <stdio.h>
    #include <stdlib.h>
    
    #define UNUSED_PARAMETER(x)  ((void)(x))
    
    int main(int argc, char *argv)
    {
        int i, j;
        char buf[4096][4096];
        
        UNUSED_PARAMETER(argc);
        UNUSED_PARAMETER(argv);
        
        for (i=0; i<4096; i++)
            for (j=0; j<4096; j++)
                buf[i][j] = 1;
            
        return 0;
    }

    欢迎交流,如有转载请注明出处

    新浪博客:http://blog.sina.com.cn/u/2049150530
    博客园:http://www.cnblogs.com/sky-heaven/
    知乎:http://www.zhihu.com/people/zhang-bing-hua

  • 相关阅读:
    [转载] $CF652B$ 题解
    [转载] $Luogu$ $P4951$ 题解
    luoguP3723 HNOI2017 礼物
    动态dp学习笔记
    noip级别模板小复习
    noip2017简要题解。
    noip考前抱佛脚 数论小总结
    HDU 6071 Lazy Running
    POI2012 ODL-Distance
    [NOI2002]荒岛野人
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/5883496.html
Copyright © 2011-2022 走看看