views:

278

answers:

2

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
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
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
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