Child Process & Parent Process Data :: Win32

Started by
5 comments, last by kuphryn 21 years, 7 months ago
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
Advertisement
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).
daerid@gmail.com
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
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Thanks.

I am not working on anything in particular. I just want to get a clear understanding of multiprocessing.

Kuphryn

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.

"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
Nice examples. Thanks.

Kuphryn

This topic is closed to new replies.

Advertisement