派生进程之间共享一个全局变量 [英] Sharing a global variable between forked processes
本文介绍了派生进程之间共享一个全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个全局变量,X.然后我叉,从孩子修改的X.我想这些变化在父显示出来,但我不希望父母要等上了孩子。
I have a global variable, X. I then fork and modify X from the child. I want those changes to show up in the parent, but I don't want the parent to have to wait on the child.
我怎样才能做到这一点?
How can I do this?
推荐答案
您需要把变量共享内存。有许多方法来创建共享内存。我可能只是使用 MMAP
,但你也可以看看 shmget的
或的shm_open
。
You need to put the variable in shared memory. There are many ways to create shared memory. I'd probably just use mmap
, but you could also check out shmget
or shm_open
.
这篇关于派生进程之间共享一个全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文