开发者

Interprocess Communication Unix C

I have two processes, A and B. B is a process that performs some functions. Process A is the one that controls B. i.e Process A instruct process B by providing data (control and functional) to it.

I have a thread in B dedicated to IPC, All that thread does is to get instructions from process A while the other threads which are running do whatever they h开发者_JS百科ave to with the already existing data.

I thought of pipes and shared memory using shmat. But i am not satisfied, I want something like, whenever Process A writes a msg to B, only then should the ipc thread in B has to wake up.. Any idea as how to acheive this?


The specifics sort of depend on what kind of flexibility you need and who is using what pipes, but this should work: Have process B's IPC thread select for readability on the pipe. When process A writes to the pipe, process B's IPC thread will be awoken.


I found a solution. I made one of the threads open one end of the pipe for read, do the actual read and close it. This goes on in a while loop which is infinite one!

The process which wants to write to it will open it only when it needs to write and close it and will eventually end.

Infact this setup avoids synchronisation issues as well. But I don know what are the consequences of it though interms of performances!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜