shared memory unix c/c++
Posted on 2003-03-31
Here's what I know about shared memory (programming) and what i have in my program so far. most of this was provided by my professor.
i need to include these header files:
int shmget (long key, int nbytes, int flags)
will get me nbytes bytes of shared memory and returns a shared memory id:
so i want 2 shared variables of 8 byte each in my program i used:
int shmid = shmget(key, 8, 0666 | IPC_CREAT);
int shmid2 = shmget(key, 8, 0666 | IPC_CREAT);
char *shmat (int shmid, int address, int flags)
It "attaches the shared memory segment to an address space"
so in my program I have:
char *variable1 = shmat(shmid, 0, 0);
char *variable2 = shmat(shmid2, 0, 0);
however, when compiling, it says void* cannot be used to initilize type char*.
also, i tried a normal assignment statement, and it tells me void* cannot be assigned to char*.
However, my professor said otherwise.
Can someone help me with what I'm trying to do?
Basically I want to share 2 8 byte strings among 4 processes (3 of which are fork()ed from the main process).