Archived

This topic is now archived and is closed to further replies.

Child Process & Parent Process Data :: Win32

This topic is 5575 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. How do you pass data and/or pointer to data in a parent process, both primary and/or child threads, to the primary thread (default) of a child process? Jeffrey Richter demonstrates the use of CreateProcess(), but he does not discuss a way to pass in data. Thanks, Kuphryn

Share this post


Link to post
Share on other sites
You might wanna consider using Threads instead of creating a child process, as every process gets its own address space and is essentially completely unaware of any other process running.

Multiple concurrent threads run in the address space of the process that started them, therefore they are able to access data and variables in that process (using synchronization, of course).

Share this post


Link to post
Share on other sites
Thanks.

Yeah. I was just wonder how about passing data from the parent process one or more child processes.

For example, let say you spawn a child process that will decode a JPEG picture. However, the JPEG binary is stored in the parent process. How do you pass data to the child process?

In general, I do not quite understand child process. For instance, with threads, you pass to it a function that does work. With a process, I do not know if you could pass in a worker function. The only use I could see for a child process is shawn a separate program, i.e. openning notepade.exe.

Kuphryn

Share this post


Link to post
Share on other sites
Yes, Richter''s book could do a better job of dealing with "inter process communication" (IPC). There are several different IPC methods. Pipes, mailslots, Dynamic Data Exchange (DDE), memory mapped files, and system wide hooks and maybe a couple of others too. Google on "inter process communication" and you should be able to find the relevant MSDN links.

A typical approach used in conjunction with CreateProcess is inherited pipes - however there are a few problems with using that approach on Win9x. What is it you want to do? Perhaps someone will be able to recommend a specific approach well suited to your task.

Share this post


Link to post
Share on other sites
One other approach that I forgot to mention is to send a WM_COPYDATA message - very simple, but quirky too.

From what you describe, a thread is probably a better approach to take. For example, pass a handle to the jpg resource to the thread function which in turn performs the decoding such that the bits are ready for the main thread to render.

One major benefit of launching a child process is that the spawned process lives and dies on it''s own. For example, many IDE''s do this to compile and link a file. Any errors that might occur in the child process do not effect the parent process. Another example is a debugger. In typical use, a debugger acts as a parent process that spawns a child and then waits for it to throw - at which point the debugger wakes up and reports information about the error thrown by the child - among the many other things that debuggers do. Another example is in situations where you have a console program that runs continuously but you don''t want to keep a console window open all the time - in that case, one could write a dialog based program that sits in the tray and acts as a controller on a spawned child process that was sharted in hidden mode. I wrote something like that to run Apache on W98 a couple of years ago before the Apache people built that feature into the software.

Share this post


Link to post
Share on other sites