问题
I am testing the shared memory using the boost. Also, i've noticed that i can use the shell command "ipcs -m" to check how many shared memory now in my system. After i ran the code below, the application worked well, but, i cannot see the shared memory created by the application via the command "ipcs -m" Can anyone tell me why? what should i do to check the shared memory except ipcs?
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/mapped_region.hpp>
#include <iostream>
int main(int argc, char** argv)
{
boost::interprocess::shared_memory_object shdmem(boost::interprocess::open_or_create,
"shm_data", boost::interprocess::read_write);
shdmem.truncate(1024);
std::cout << "created shm: " << shdmem.get_name() << std::endl;
boost::interprocess::offset_t size;
if (shdmem.get_size(size))
{
std::cout << "shm size: " << size << std::endl;
}
boost::interprocess::mapped_region region(shdmem, boost::interprocess::read_write);
char *s = static_cast<char*>(region.get_address());
strcpy(s, "Hello, world!");
std::cout << "write shm finished." << std::endl;
boost::interprocess::mapped_region region2(shdmem, boost::interprocess::read_only);
char *i2 = static_cast<char*>(region2.get_address());
std::cout << "read shm finished, value: " << i2 << std::endl;
return 0;
}
来源:https://stackoverflow.com/questions/56021045/i-cannot-see-the-shared-memory-created-by-the-boostinterprocess-via-shell-comm