لماذا بعض posix الذاكرة المشتركة قطاعات posix الإشارات غير مرئية ipcs

StackOverflow https://stackoverflow.com/questions/880127

سؤال

لقد بنيت عميل ملقم التطبيق باستخدام posix الذاكرة المشتركة و posix اسمه الإشارات مع pshared=1.فإن الإشارات يتم وضعها داخل الذاكرة المشتركة.البرنامج يعمل بشكل جيد ولكن عندما كنت اكتب ipcs -m أو ipcs -s, أنا لا أرى أي مشترك شرائح الذاكرة أو الإشارات التي تم إنشاؤها.لماذا هو كذلك ؟

/* 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 الدليل.

نصائح أخرى

والدولي للسلامة الكيميائية يعرض معلومات عن النظام نظام V IPC. الإشارات POSIX والذاكرة المشتركة هي نظام مستقل (وأفضل) والتي لا ترصدها "الدولي للسلامة الكيميائية.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top