0

boost::interprocess will create a shm like this:

boost::interprocess::managed_shared_memory segment(boost::interprocess::open_or_create, "ContainerSharedMemory", 65536);

but how can a watch this shm like this:

/Tool/SHMCache$ ipcs -m

key        shmid      owner      perms      bytes      nattch     status      
0x00005feb 0          root       666        12000      2                       
0x00005fe7 32769      root       666        524288     2                       
0x00005fe8 65538      root       666        2097152    2                       
0x0001c08e 98307      root       777        2072       0                         
Jean Davy
  • 2,062
  • 1
  • 19
  • 24
Dylan Wang
  • 111
  • 8

1 Answers1

1

managed_shared_memory is for cross-platform use which uses a BasicManagedMemoryImpl pointer to internal implementation on different OSes. For example, it uses basic_managed_windows_shared_memory as backend on Windows. managed_shared_memory doesn't have a method to get shmid for the sake of portability. If you OS supports system V shared memory, you can use basic_managed_xsi_shared_memory which has get_shmid() method and nearly the same interface as basic_managed_shared_memory. A simple example:

#include <boost/interprocess/xsi_shared_memory.hpp>
#include <boost/interprocess/mapped_region.hpp>

using namespace boost::interprocess;

int main(int argc, char *argv[])
{
    //Build XSI key (ftok based)
    xsi_key key(argv[0], 1);
    //Create a shared memory object.
    xsi_shared_memory shm (create_only, key, 1000);
    // TODO Remove if exists
    printf("shmid: %d\n", shm.get_shmid());
}

Then you can see it with ipcs -m if share memory is created successfully.

jfly
  • 7,715
  • 3
  • 35
  • 65
  • System V is fully supported by Linux kernels. Of course you can run the simple program on linux. – jfly Apr 21 '16 at 00:38
  • thanks,i will try this. and how can i get more detail about managed_shared_memory – Dylan Wang Apr 21 '16 at 00:46
  • [boost docs](http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/managed_memory_segments.html#interprocess.managed_memory_segments.managed_shared_memory.windows_managed_memory_common_shm) talk a little about this. – jfly Apr 21 '16 at 01:09