I am trying to write a program in which child processes interact with each other on Linux.
All these processes are created from the same program, and they share the code.
I need them to have access to two integer variables, as well as an integer array.
I have no idea how shared memory works, and every resource I searched for doesnβt change anything, but confuse me.
Any help would be greatly appreciated!
Edit: Here is an example of some code that I have written so far to split one int, but it is probably wrong.
int segmentId; int sharedInt; const int shareSize = sizeof(int); segmentId = shmget(IPC_PRIVATE, shareSize, S_IRUSR | S_IWUSR); sharedInt = (int) shmat(segmentId, NULL, 0); shmdt(sharedInt); shmctl(segmentId, IPC_RMID, NULL);
c shared-memory
Josh
source share