Can I resize Linux shared memory with shmctl?

后端 未结 3 2142
情话喂你
情话喂你 2021-02-20 03:03

I have a C++ application that allocates shared memory on a Linux system via shmget(2). The data that I store in the shared memory grows periodically, and I\'d like to resize th

3条回答
  •  有刺的猬
    2021-02-20 03:41

    It seems to me that the function mremap was implemented to perform what you want. You just have to precise in argument the old size and the new one of the shared memory segment. And if you add the flag MREMAP_MAYMOV, it allows to move the shared memory segment if needed (i.e if not enough free space just after the old shared memory segment).

    Look at the manpage : http://man7.org/linux/man-pages/man2/mremap.2.html.

提交回复
热议问题