
那么当shm_open()还不知道大小时,它是如何首先创建内存区域的?如果不是这样,我完全错了,那么请告诉我shm_open()和ftruncate()的目的.提前致谢!!!
解决方法 shm_open的要点是你可以打开一个现有的内存区域.但是,如果它不存在并且你创建它,shm_open在创建文件时表现得像open;新创建的内存区域大小为0.从 Linux manuals开始:
O_CREATCreate the shared memory object if it does not exist. The user and group ownership of the object are taken from the corresponding effective IDs of the calling process,and the object’s permission bits are set according to the low-order 9 bits of mode,except that those bits set in the process file mode creation mask (see umask(2)) are cleared for the new object. A set of macro constants which can be used to define mode is Listed in open(2). (Symbolic deFinitions of these constants can be obtained by including .)
A new shared memory object initially has zero length–the size of the object can be set using
ftruncate(2).The newly allocated bytes of a shared memory object are automatically initialized to 0.
(强调我的)
由于shm_open不会将新创建的区域的大小作为参数(它会使系统调用/库调用复杂化以便为各种情况添加参数),因此必须使用ftruncate()来更改已打开的共享内存区域的大小从它的初始大小.
当然,您不必将ftruncate用于已正确创建并在其他位置调整大小的共享内存段.如果您想知道它的大小,请使用fstat.另见shm_overview(7)
以上是内存溢出为你收集整理的shm_open()和ftruncate()的目的是什么?全部内容,希望文章能够帮你解决shm_open()和ftruncate()的目的是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)