Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of /dev/shm on Mac OS X

I am working on a shared memory assignment 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 snippets in the program is the above.

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

In shm_open(): File exists

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

Where is the location of my_shared_memory so I can delete it?

like image 484
theGreenCabbage Avatar asked Oct 20 '22 07:10

theGreenCabbage


1 Answers

The simplest solution to your problem is not using

O_EXCL

if you don't want that behaviour.

Generally, shared memory objects do have a name, but it's not really a file name -- you can't generally delete them. It's good POSIX style to display them under /dev/shm, but this depends on your OS:

My best guess would be that you should read what man shm_open says on your machine.

like image 185
Marcus Müller Avatar answered Nov 02 '22 09:11

Marcus Müller