美文网首页
验证子线程分配的内存空间在内存映射区

验证子线程分配的内存空间在内存映射区

作者: 书唐瑞 | 来源:发表于2019-10-27 18:27 被阅读0次
    #include <stdio.h>
    #include <stdlib.h>
    #include <pthread.h>
    #include <unistd.h>
    #include <sys/types.h>
    
    void *threadFunc(void *arg)
    {
        void *ptr = malloc(1000);
        printf("thread heap'addr = %p\n", ptr);
    
        int i = 3;
        printf("thread stack'addr = %p\n", &i);
        getchar();
    }
    
    
    int main()
    {
    
        pthread_t child;
        pthread_create(&child, NULL, threadFunc, NULL);
    
        sleep(10000);
    
        return 0;
    }
    
    

    结果打印


    子线程的栈空间和堆空间地址

    查看进程的maps


    进程maps

    相关文章

      网友评论

          本文标题:验证子线程分配的内存空间在内存映射区

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