标题:获取到的共享内存地址无法访问
只看楼主
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
结帖率:81.82%
 问题点数:0 回复次数:2 
获取到的共享内存地址无法访问
程序代码:
{
    unsigned int iShmId = 0;
    unsigned int uiShmKey = 0x10724;
    unsigned int *ptest = RRM_PNULL;

    iShmId = shmget_wrapper(uiShmKey, 0, (IPC_CREAT | 0666));
    if (iShmId >= 0)
    {
        fprintf(stderr, "iShmId(%d) exist\n", iShmId);
        /* IF key exist then remove SHM*/
        shmctl_wrapper_ipc_rmid(iShmId);
    }

    /* Get the shared memory ID */
    iShmId = shmget_wrapper(uiShmKey, sizeof(unsigned int),(IPC_CREAT | 0666));
    if (0 > iShmId)
    {
        fprintf(stderr, "SHM(%d) get failed\n", uiShmKey);
        return;
    }

    /* Map Shared memory */
    ptest = (unsigned int *)shmat_wrapper(iShmId, RRM_PNULL, 0);   
    fprintf(stderr,"ptest(%p)", ptest);
    if ((void *)-1 == ptest)
    {
        fprintf(stderr,"SHM(%d) attach failed", uiShmKey);
        shmctl_wrapper_ipc_rmid(iShmId);
        iShmId = -1;
        return;
    }

    /* Initialize shared memory */
    memset(ptest, 0, sizeof(unsigned int));   
    fprintf(stderr,"SHMend", uiShmKey);
}
搜索更多相关主题的帖子: 地址 unsigned int fprintf memory 
2019-06-01 17:44
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
得分:0 
程序没有返回错误,但是运行到最后metset就会挂死
2019-06-01 17:46
w906414
Rank: 2
等 级:论坛游民
帖 子:75
专家分:76
注 册:2015-5-29
得分:0 
上面的代码有问题,使用的是unsigned int,但后续全部改为int之后,依然是memset挂死
2019-06-01 17:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-495056-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.154599 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved