按名称列出 Solaris 上的共享内存对象

发布于 2024-08-09 09:31:32 字数 173 浏览 2 评论 0原文

我可以使用 ipcs(1) 列出 Solaris 10 机器上的活动共享内存对象,但它是按键列出的。不过,我通过 shm_open(3) 打开对象,它采用字符串作为名称来标识对象。有没有办法按名称列出共享内存对象,或者只获取键<->名称映射?我最感兴趣的是从命令行运行的东西,尽管用于执行此操作的 API 也可以。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清音悠歌 2024-08-16 09:31:32

据我所知,Solaris 下的 POSIX 共享内存出现在文件系统上,或者直接在 /tmp/ 下作为 .SHMDxxx 文件,或者在 /var/tmp/ 下。 SHMD/。这可能对您有帮助,也可能没有帮助,而且我没有方便的 Solaris 盒子来验证。

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.

旧人 2024-08-16 09:31:32

我不知道如何列出名称或获取键/名称映射。但我想我知道一个 API 可以解决你的问题。

我认为您可以使用 System V 接口(也是 Posix API)附加密钥中的段。我相信它的工作方式是这样的:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文