gpt4 book ai didi

c - 当段已经存在时,如何使用 shmget 权限位?

转载 作者:太空宇宙 更新时间:2023-11-04 03:28:56 26 4
gpt4 key购买 nike

假设我使用以下参数调用 shmget:

int shmid = shmget(KEY, 1024*4096, IPC_CREAT|0644);

进一步,假设具有键 KEY 的段已经存在。 shmgetshmflg 参数(在本例中为 0644)中的权限模式位如何影响 shmget的行为? shmget 是否对具有这些权限标志的段的权限执行任何类型的权限验证?具体来说,该验证需要什么?

最佳答案

How do the permission mode bits OR'd into the shmflg argument [...] of shmget affect shmget's behavior?

POSIX对于已经存在指定键的共享内存段的情况,解释这个问题有点棘手,但其意图似乎是它与 open() 类似地运行。即如果进程的uid、gid和请求的mode与段的uid、gid、权限不一致,则函数失败。具体来说,

The shmget() function shall fail if: [...] A shared memory identifier exists for key but operation permission as specified by the low-order nine bits of shmflg would not be granted [...].

shmget() 的 Linux 联机帮助页中有类似的文字,并且还特别说明了这一点

If the shared memory segment already exists, the permissions are verified [...].

这与 POSIX 没有区别,只是更明确。

Another section of POSIX提供更多详细信息,归结为根据进程的 euid 和 egid,根据适用于该进程的权限位集授予或拒绝读取/和/或写入访问权限。

Does shmget perform any kind of "permission verification on the permissions of the segment with these permission flags? Specifically what does that verification entail?

是的,如上文和链接的 POSIX 规范中所述。

shmflg的低九位指定的操作权限”是什么,我还是不太清楚。可以将其解释为调用进程在创建段时对段具有的权限,但我认为这实际上意味着 shmflag 中打开的所有模式位也是在段的权限字段中打开。

关于c - 当段已经存在时,如何使用 shmget 权限位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38750811/

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