How can I share data between child and parent in Linux (not Windows)?
Source files:
1.h
extern int a;
extern int b;
2.h
#include "1.h"
void adder();
2.c
#include "2.h"
void adder()
{
a++;
b++;
}
1.c
#include "1.h"
#include "2.h"
int a = 0;
int b = 0;
int main()
{
pid_t pid;
pid = fork();
while (1) {
if (pid == 0) {
adder();
}
printf("a: %d , b: %d\n", a, b);
}
return 0;
}
result
a: 0 b: 0
How can I share the values of a
and b
? I want to get the result that a
and b
are increasing.