Location of / dev / shm on Mac OS X

I am working on shared memory allocation on Mac OS X

    #define SHARED_OBJECT_PATH    "/my_shared_memory"

    fd = shm_open(SHARED_OBJECT_PATH, O_CREAT | O_EXCL | O_RDWR, S_IRWXU | S_IRWXG);
    if (fd < 0) {                                                         
        perror("In shm_open()");                                          
        exit(1);                                                          
    }

One of the small fragments of the program is above.

When I compile and run the program a second time, I get an error:

In shm_open(): File exists

I assume that I need to manually delete using rm [path_to]/my_shared_memory. I know on Linux, this is the default dev/shm, however this path does not exist on Mac OS X.

Where is it located my_shared_memoryso I can delete it?

+4
source share
1 answer

The easiest solution to your problem is not to use

O_EXCL

if you do not want this behavior.

, , - . POSIX, /dev/shm, :

, , man shm_open .

+2

All Articles