开发者

Shared variables between two independent processes

开发者 https://www.devze.com 2023-04-08 12:04 出处:网络
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.

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.


Use a memory mapped file: http://en.wikipedia.org/wiki/Memory-mapped_file

0

精彩评论

暂无评论...
验证码 换一张
取 消