fork() and IPC

Hey all. I recently ported a multithreaded program from WinNT to LINUX using pthreads. Everything works fine, except that it turns out the drivers for the hardware I'm working with aren't thread safe. So, now I have to find a way to make this multi-process instead of multi-threaded.

I just started working with fork(), and am having a little trouble following the interprocess communication models. Is there an "easy" way to allow a child process(es) to have access to the global variables in the parent process? This is the way the original programmer did it under NT multithreaded, and I'd rather not rewrite the entire app (it's big).

The primary way to share data between processes using UNIX IPCs are:

(1) Shared memory;

(2) Sockets:

There are other UNIX IPCs including

(3) Message Queues.

(4) Semaphores;

(5) Signals.

Your best best (for IPCs) is to use shared memory segments, based on your post. You might need to use semaphores to insure that the shared memory operations are atomic.