开发者

listing shared memory objects on Solaris by name

I can use ipcs(1) to list out the active shared memory objects on a Solar开发者_JAVA百科is 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!


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.


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;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜