c - Purpose of shm_open() and ftruncate()? -
when create shared-memory use shm_open()
, ftruncate()
function. according information shm_open()
create shared-memory region. , use ftruncate()
function configure size of shared-memory region.
well how shm_open()
creates memory region in first place when doesn't yet know size? , if not case , totally wrong, please tell me purpose of shm_open()
, ftruncate().
in advance!!!
the main point of shm_open
can open existing memory area. in case didn't exist , you'd create it, shm_open
behaves open
when creating file; newly created memory area has size of 0. linux manuals:
o_creat
create shared memory object if not exist. user , group ownership of object taken corresponding effective ids of calling process, , object's permission bits set according low-order 9 bits of mode, except bits set in process file mode creation mask (see umask(2)) cleared new object. set of macro constants can used define mode listed in open(2). (symbolic definitions of these constants can obtained including .)
a new shared memory object has 0 length--the size of object can set using
ftruncate(2).
newly allocated bytes of shared memory object automatically initialized 0.
(emphasis mine)
since shm_open
not take size of newly created area argument (it'd complicate system call / library call add arguments sorts of cases), ftruncate()
must used change size of opened shared memory area initial size.
of course not have use ftruncate
shared memory segment created , resized elsewhere. should want know size, use fstat
. see shm_overview(7)
Comments
Post a Comment