I need my parent and child process to both be able to read and write the same variable (of type int) so it is "global" between the two processes.
I'm assuming this would use some sort of cross-process communication and have one variable on one process being updated.
I did a quick google and IPC and various techniques come up but I don't know which is the most suitable for my situation.
So what technique is best and could you provide a link to a noobs tutorial for it.
Thanks.
Since you are mentioning using fork(), I assume that you are living on a *nix-System
From Unix.com
A tutorial on forking and shared memory is on dev shed:
http://forums.devshed.com/c-programming-42/posix-semaphore-example-using-fork-and-shared-memory-330419.html
another more in-depth description of using multithreading (if appilcable for your application) can be found here:
https://computing.llnl.gov/tutorials/pthreads/
A variant that I used recently of shared memory is to open a mmap before forking. This avoids certain restrictions of the shared memory api. You don't have a size limit (the address range is limit), you don't need to generate the key from that absolute file. Here an example how I did it (I left out the error checking for the sake of brevity)
If you need to share memory, perhaps using threads instead of processes would be a better solution?