Chris D
Chris D

Reputation: 75

Communicating between two processes

This has been discussed before, but I've struggled with the responses, so was hoping for a clearer answer tailored to my situation:

I'm developing an application in C++ under 32-bit Windows (minimum requirement is WinXP) which need to communicate across two processes.

The remit is that process 1 (p1) needs to start process 2 (p2), then call various functions of p2. I need p1 to stop what it is doing until the p2 function that it calls has finished, and then continue where it left off.

What would be the best kind of methods for me to research so that I can do something like this?

All the best,

Chris

Upvotes: 2

Views: 2277

Answers (4)

André Caron
André Caron

Reputation: 45284

I know Remote Procedure Call sounds more sexy as it removes the need to design your own "communication protocol" and serialize your own requests and responses, but what about just writing two processes that communicate through an anonymous pipe or socket?

You can have the 2nd process inherit a handle to the pipe/socket. Then, it can simply serve requests from the 1st process by blocking on the pipe for a request. The 1st process can simply write a request on the pipe/socket and wait for the reply by blocking on the socket.

Upvotes: 3

mkaes
mkaes

Reputation: 14129

If it is only about calling functions/methods in the other process and only Windows you can also take a look at Microsoft Remote Procedure Call.
If you need to share lots of data you are better of with the named semaphores and shared memory.

Upvotes: 2

Puppy
Puppy

Reputation: 147028

Mutexes in Win32 are cross-process synchronization. You could also look into using a condition variable, but I'm not sure if cross-process varieties of those exist.

Upvotes: 1

Pete Wilson
Pete Wilson

Reputation: 8704

Try reading about Win32 semaphores, perhaps emphasizing semaphore-based Win3e2 events. Events allow p1 <--> p2 communication. If the two processes need to pass a lot of values back and forth, you can read about shared memory. Both of these mechanisms are very standard and usual ways of interprocess communication.

Upvotes: 0

Related Questions