For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > December 2006 > Re: How to write a structure that has pointers in the shared









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How to write a structure that has pointers in the shared
Rob Hoelz

2006-12-19, 7:10 pm

"barkha" <barkhashah@gmail.com> wrote:

> Hi All,
> I want a help on some piece of code that can demonstrate how to wrtie
> this structure in the shared memory? I have some child processes that
> are going to write these structures in the shared memory and parent
> process is suppose to pull these structures out of the shared memory.
>
> typedef struct AgentReq {
> int command;
> short numParms;
> short maxParms;
> int requestType;
> const void **parm;
> int *parmType;
> int *parmLen;
> } AgentReq;
>
> PS: The structure is already allocated from heap and the data members
> are already populated. Now they need to be put in the shared memory by
> all the child processess who are working on this structure.
> Uptill now in my current architecture ,child processes used to
> communicate with the parent process about the above structure using
> the TCP/IP socket. Parent process used to listen on localhost :
> <someport> and child processes used to send these structures one by
> one to the parent process using socket.
> Now I want to avoid opening the socket for communication between child
> and parent process and henceforth want to make use of shared memory.
> This topic has nothing to do with any platform. It has more to do with
> teaching me how to read and write the above structure in the shared
> memory. I have learned that shared memory should never contain
> pointers and Instead of pointers one should write offset in bytes from
> start of shared memory. I want to know HOW? Can anyone please explain
> me in terms of C language?
> A quick help on this will be appreciated.
> Thanks.
>


Well, since you're using parent and child processes, you could (and
probably should) use pipes to communicate data between them. Check the
man page for popen to see how.
--
-Rob Hoelz
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com