我如何共享亲子过程,当他们死时自动释放内存之间的内存 [英] How can i share memory between parent-child process that free the memory automatically when they die

查看:85
本文介绍了我如何共享亲子过程,当他们死时自动释放内存之间的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的mmap,但据我知道如果我想分享由父进程分配的内存,并通过客户端进程访问它,我需要创建一个临时文件。

I know about "mmap", but as far as i know if i want to share memory allocated by a parent process and accessed it by a client process i need to create a temporary file.

不过,这个文件将继续,如果死的进程存在。

But this file will continue to exist if the processes die.

我的教育,永远不会离开垃圾落后。无论是在现实生活中,并在节目。

I was educated to never leave garbage behind. Both in real life and in programming.

该解决方案应该在Linux,FreeBSD和Solaris的工作。

The solution should work on Linux, FreeBSD and Solaris.

推荐答案

上述命名管道应该为你做。您可以使用两个管道(如果可能):

Named Pipes should do for you as mentioned above. You can use two pipes (if possible) :


  1. parentpid_childpid - 家长写和孩子在读

  2. childpid_parentpid - 儿童写和读parebt

这对我的作品。如果您有任何特殊senarios考虑请注明。

This works for me. Please mention if you have any special senarios to consider.

这篇关于我如何共享亲子过程,当他们死时自动释放内存之间的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆