I am trying to share a variable value between two C programs which run independently from each other therefore each of it uses separate memory, I used a share.h header file with extern statement but it does not work, I also used a txt file to which I write the variable from one C program and read it with the 2nd C program from there but there are sync problems and permission problem to read the file, any ideas how to solve this issues or how to effectively share a variable value?
Asked
Active
Viewed 500 times
1
-
2You might want to read about [shared memory](http://en.wikipedia.org/wiki/Shared_memory_%28interprocess_communication%29), or other [inter-process communications](http://en.wikipedia.org/wiki/Inter-process_communication) methods. – Some programmer dude May 15 '15 at 12:26
-
There are lots of ways of doing "interprocess communication" if you are on unix look at semphores and shared memory or using a named pipe – Vorsprung May 15 '15 at 12:27
-
I am at windows how can I use a named pipe or even create it ? I have no idea – 101 May 15 '15 at 12:30
1 Answers
1
I dont think that it is possible just by adding the headers as the two programs will have there own memeory space. So you cant communicate both by just adding the headers.
You probably need to use some IPC mechanism
On a side note:
extern
is generally used to share variables between two C files which are part of the same program, but you cannot use it between two different programs.

Rahul Tripathi
- 168,305
- 31
- 280
- 331