两个独立进程之间的共享变量
我有一个守护进程正在运行并完成其工作。我希望能够在它运行时从中收集统计信息。我的环境是Linux,编程语言是C。
一种选择是让守护进程写入某个日志文件,然后解析/分析该文件以获取统计信息。此选项不提供在不重新启动守护进程的情况下更改采样率的灵活性。此外,它还涉及解析日志文件。
另一种选择是在守护进程和统计收集器进程之间使用共享内存。这需要在修改到共享区域时手动复制所有受监视的变量。
使用管道或套接字并不可取,因为它需要阻塞或创建新线程。
我想知道是否有诸如共享内存之类的技术,但我需要能够将进程变量与共享区域内的特定地址相关联。每当变量更改时,我不需要自己复制变量。
欢迎任何建议。
编辑:
我实际上想要的是Linux上的/proc
文件系统,但用于用户空间进程。
I have a daemon process running and doing its job. I want to be able to collect statistics from it while it is running. My environment is Linux and the programming language is C.
One option is to make the daemon process writes to some log file and parse/analyse the file later to get the statistics. This option does not provide the flexibility to change the sampling rate without restarting the daemon process. Also, it involves parsing log files.
Another option is to use shared memory between the daemon process and the statistics collector process. This requires copying manually all monitored variables whenever modified to the shared region.
Using pipes or sockets is not preferable as it requires blocking or creating new threads.
I am wondering if there is some technique like shared memory, but I need to be able to associate the process variables with this specific addresses within shared region. Whenever the variable is changed, I don't need to copy the variable myself.
Any suggestions are welcome.
EDIT:
What I want actually is like /proc
file system on Linux but for user-space processes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用内存映射文件:http://en.wikipedia.org/wiki/Memory-mapped_file
Use a memory mapped file: http://en.wikipedia.org/wiki/Memory-mapped_file