Sharing heap memory with fork()

前端 未结 5 1182
半阙折子戏
半阙折子戏 2021-02-15 11:53

I am working on implementing a database server in C that will handle requests from multiple clients. In order to do so I am using fork() to handle connections for individual cli

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-15 12:26

    Would it suffice to share the root pointer of the database or do I have to make all allocated memory as shared?

    No, because each process will have a its own private memory range. Copy-on-write is a kernel-space optimization that is transparent to user space.

    As others have said, SHM or mmap'd files are the only way to share memory between separate processes.

提交回复
热议问题