0
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
int x = 10;
pid_t p = fork(), t = fork(), s = fork();
printf("PID = %d -> pai: %d -> x = %d\n", getpid(), getppid(), x);
return 0;
}

hi. I need to change the code above, need increment 2 (value on x) to each of the 7 childs. i tried with if but the code repeat the fathers.

JeTups
  • 1
  • I believe you'd need to explicitly have some shared memory between them. When forking, the child is given a copy (on-write) of the parent's memory. `x` will have the same address in all processes, but they aren't the same variable. – Carcigenicate Jun 18 '20 at 13:54
  • Does this answer your question? [How to share memory between process fork()?](https://stackoverflow.com/questions/13274786/how-to-share-memory-between-process-fork) – Carcigenicate Jun 18 '20 at 14:04

0 Answers0