我建立了一个客户服务器应用程序使用posix共享存储器和posix未命名的信号与pshared=1个。该信号都放在里面的共享内存。该程序运行良好,但是当我的类型化学品安全方案-m或国际化学品安全方案,我没有看到任何共享内存段或信号,我创造的。为什么会这样呢?

/* Server main function for implementing client server program using Posix Shared Memory and Posix Unnamed Semaphores*/  
#include "shm_sem.h"
int main(int argc,char ** argv)  
{  
    int fd;  
    struct shmstruct *ptr;  
    shm_unlink(MYSHM); // delete shared memory segment, if it already exists     
    /* create shared memory, set its size, map it and close descriptor */
    fd=shm_open(MYSHM,O_RDWR|O_CREAT|O_EXCL,0777);  
    ptr=mmap(NULL,sizeof(struct shmstruct),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);  
    // truncate the size of shared memory to the size of shmstruct  
    ftruncate(fd,sizeof(struct shmstruct)); 
    close(fd);  
    // initialize the semaphores in shared memory  
    sem_init(&ptr->client_mutex,1,1); // set client semaphore to 1  
    sem_init(&ptr->server_mutex,1,0); // set server semaphore to 0  
    for(;;)
        {
        serverPosixShmSem(ptr); // calling server
        }  
}

/* Server main function for implementing client server program using Posix Shared Memory and Posix Unnamed Semaphores*/  

#include "shm_sem.h"
int main(int argc,char ** argv)  
{  
    int fd;  
    struct shmstruct *ptr;  
    shm_unlink(MYSHM); // delete shared memory segment, if it already exists     
    /* create shared memory, set its size, map it and close descriptor */
    fd=shm_open(MYSHM,O_RDWR|O_CREAT|O_EXCL,0777);  
    ptr=mmap(NULL,sizeof(struct shmstruct),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);  
    // truncate the size of shared memory to the size of shmstruct  
    ftruncate(fd,sizeof(struct shmstruct)); 
    close(fd);  

    // initialize the semaphores in shared memory  
    sem_init(&ptr->client_mutex,1,1); // set client semaphore to 1  
    sem_init(&ptr->server_mutex,1,0); // set server semaphore to 0  
    for(;;)
    {
        serverPosixShmSem(ptr); // calling server
    }  
}
有帮助吗?

解决方案

几个问题:

  • 你跑 ipcs 作为同一用户,创造共享存储器/信号灯(或者为超级用户)?
  • 你跑 ipcs 虽然该程序运行?(你确定这不是除去他们的时候离开?)

更新:

实际上,在阅读这个 螺纹 我不确定国际化学品安全方案应该能够显示POSIX信号灯。我试过你的代码样本(与一些编辑修复编译错误),你可以看到共享存储器段 /dev/shm 目录。

其他提示

IPCS显示系统V IPC系统上的信息。 POSIX信号和共享存储器是其不受“IPCS”。

监视的独立(和更好的)系统
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top