gpt4 book ai didi

linux - shmget() 返回的 shmid 是否跨进程唯一?

转载 作者:太空狗 更新时间:2023-10-29 11:14:20 24 4
gpt4 key购买 nike

这是我无法真正弄清楚的事情:如果您在 Linux 上使用相同的 key 但在不同的进程中调用 shmget(),您是否会返回相同的 shmid? shmid 是像文件描述符编号这样的临时值,还是可以跨调用保留的值?

最佳答案

是的,您将收到相同的 shmid。共享内存描述符是内核级的,而不是进程级的。 ipcs -m 列出共享内存段。

来自 man shmctl :

A successful IPC_INFO or SHM_INFO operation returns the index of the highest used entry in the kernel's internal array recording information about all shared memory segments. (This information can be used with repeated SHM_STAT operations to obtain information about all shared memory segments on the system.) A successful SHM_STAT operation returns the identifier of the shared memory segment whose index was given in shmid. Other operations return 0 on success.

来自 man shmoverview

POSIX shared memory objects have kernel persistence: a shared memory object will exist until the system is shut down, or until all processes have unmapped the object and it has been deleted with shm_unlink(3)

关于linux - shmget() 返回的 shmid 是否跨进程唯一?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23095076/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com