I can use ipcs(1) to list out the active shared memory objects on a Solaris 10 box, but it lists them by key. I'm opening the objects via shm_open(3), though, which takes a character string as a name to identify the object. Is there a way to list the shared memory objects by name, or to just get the key<->name mapping? I'm mostly interested in something to run from the command line, although an API for doing this would be OK, too. Thanks!
A:
I don't know of a way to list names or get key/name mappings. But I think I know an API that will solve your problem.
I think you can attach the segment from the key by using the System V interface, which is also a Posix API. I believe the way it works is something like:
int attach_shmem(key_t key, void** pp){
void* p;
int id;
id = shmget(key, 0, 0);
if (id < 0) {
perror("shmget");
return ERR_SHMGET;
}
p = shmat(id, 0, 0);
if ((long)p == -1) {
perror("shmat");
return ERR_SHMAT;
}
*pp = p;
return 0;
}
DigitalRoss
2009-10-28 17:48:26
A:
As far as I remember POSIX shared memory under Solaris appears on the file system either directly under /tmp/
as .SHMDxxx
files or under /var/tmp/.SHMD/
. This might or might not help you and I don't have a Solaris box handy to validate.
Nikolai N Fetissov
2009-10-28 18:36:09
Yep, `/tmp/.SHMD*` on my machine. So I was thinking their was something magical about shm_open(3), but looks like it's probably just a wrapper around open(2) that creates the backing file on an appropriate file system? Thanks!
Chris
2009-10-28 19:49:58
shm_open returns the "file" descriptor after all, which you are supposed to mmap. I might be mistaken but I guess this is done as some sort of a VFS hack (need to look into Solaris sources for this :)
Nikolai N Fetissov
2009-10-28 20:09:50